Hey all,
I'd like to ask for a little help as I followed some quick tutorials on how to get another thread in my app working. The thing I'm doing is a kind of organiser with calendar that has ability to popup reminders for the user and I'd like to use different thread for checking if there isn't any task to remind the user of and if there is show a popup with info about it. I figured a way to do it from some websites and this is what I've come up with, but unfortunately app is not responding when I try to run it:
QFuture<Task*> future = QtConcurrent::run(this, &MainWindow::checkReminders);
popupTask = future.result();
QFutureWatcher<Task*> watcher;
watcher.setFuture(future);
connect(&watcher, SIGNAL(finished()), this, SLOT(popupReminder()));
QFuture<Task*> future = QtConcurrent::run(this, &MainWindow::checkReminders);
popupTask = future.result();
QFutureWatcher<Task*> watcher;
watcher.setFuture(future);
connect(&watcher, SIGNAL(finished()), this, SLOT(popupReminder()));
To copy to clipboard, switch view to plain text mode
Above is set in MainWindow constructor.
I haven't already connected the popupTask variable to popupReminder() method, because I wanted to make it work first before providing the popup with the information to show.
Here is MainWindow::checkReminders() method:
Task* MainWindow::checkReminders() {
do {
for(int i = 0; i < daysList.count(); i++) {
for(int j = 0; j < daysList[i].getListCount(); j++) {
if(current == *daysList[i].getTaskAtIndex(j)->getReminderTime() &&
!daysList[i].getTaskAtIndex(j)->ifDone() &&
daysList[i].getTaskAtIndex(j)->ifNeededReminder()) {
daysList[i].getTaskAtIndex(j)->turnOffReminder();
return daysList[i].getTaskAtIndex(j);
}
}
}
} while (true);
}
Task* MainWindow::checkReminders() {
do {
for(int i = 0; i < daysList.count(); i++) {
for(int j = 0; j < daysList[i].getListCount(); j++) {
QDateTime current = QDateTime::currentDateTime();
if(current == *daysList[i].getTaskAtIndex(j)->getReminderTime() &&
!daysList[i].getTaskAtIndex(j)->ifDone() &&
daysList[i].getTaskAtIndex(j)->ifNeededReminder()) {
daysList[i].getTaskAtIndex(j)->turnOffReminder();
return daysList[i].getTaskAtIndex(j);
}
}
}
} while (true);
}
To copy to clipboard, switch view to plain text mode
and finally the popupReminder() method:
void MainWindow::popupReminder() {
reply
= QMessageBox::information(this, tr
("QMessageBox::information()"), MESSAGE1
);
}
void MainWindow::popupReminder() {
QMessageBox::StandardButton reply;
reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE1);
}
To copy to clipboard, switch view to plain text mode
Earlier I used checkReminders as a void method that just made the window pop up itself, but I've read somewhere that it is better not to make multiple threads take care of GUI, so I thought I'll give it a try with QFutureWatcher. If someone could point out what I'm doing wrong I'd be grateful.
Bookmarks