작업 목록을 보유하는 응용 프로그램을 만들려고하고 있으며 마감일이 다가 오면 마감일을 맞으면 기능 (팝업 표시)을 실행하려고합니다.QT C++은 특정 시간에 함수가 실행될 때까지 대기합니다.
나는이 있습니다
#ifndef TIMER_H
#define TIMER_H
#include <QWidget>
#include <QTimer>
#include <QtGui>
#include <QObject>
class Timer : public QWidget
{
Q_OBJECT
public:
Timer(QWidget * parent = 0);
void setTimer(QString title, QString description, QDate date, QTime reminderTime);
public slots:
void showWarning() {QString show = tit;
QPushButton * thanks = new QPushButton(QObject::tr("Thank you for reminding me!"));
show.append("\n");
show.append(des);
QMessageBox popup;
popup.setText(show);
popup.setWindowTitle("Calendar : Reminder");
popup.setDefaultButton(thanks);
popup.exec();
}
private:
QString tit;
QString des;
QDateTime now;
QDateTime timeoftheaction;
QTimer *timer;
};
CPP 파일 :
#endif // TIMER_H
#include "timer.h"
#include <iostream>
using namespace std;
Timer::Timer(QWidget * parent)
: QWidget(parent)
{
}
void Timer::setTimer(QString title, QString description, QDate date, QTime reminderTime)
{
now.currentDateTime();
timer = new QTimer;
tit = title;
des = description;
timeoftheaction.setDate(date);
timeoftheaction.setTime(reminderTime);
connect(timer, SIGNAL(timeout()),this,SLOT(showWarning()));
timer->start(now.secsTo(timeoftheaction)*1000);
}
그러나 기능 showWarning이 ... 컴파일 오류가, 기능 showWarning 완벽
(시험 없음) 작품이라는되고 있지 않습니다오류가 연결에 있다고 생각하지만 확실하지 않습니다 ...
'now.secsTo (timeoftheaction) * 1000'이 실제로 당신이 생각하는 것을 당신에게주는 것을 확인 했습니까? – enderland
타이머를 : timer-> start (1)'로 설정하면 즉시 작동합니까? 그렇다면 @ 엔더 랜드의 제안은 맞습니다 – jdi
이것은 해결책이 될 수도 있습니다 : http://stackoverflow.com/questions/11996706/qt-c-wait-till-specific-time-to-execute-function/14144614 # 14144614 – formiaczek