PDA

View Full Version : QTimer::singleShot(...) triggered from a QAction does not start!?



dobedidoo
9th December 2009, 12:46
In my main window I've included an option to 'Check for updates' (available from a menu). Now, I'd prefer to start this updates check using a QTimer::singleShot(...) to prevent the menu from being "frozen" while the check for updates is ongoing and I've tried with the following:

void MainWindow::sendCheckForUpdates()
{
QTimer::singleShot(200, this, SLOT(checkForUpdates()));
}

So, triggering the 'Check for updates' QAction in the QMenu starts 'sendCheckForUpdates()', which I would hope would only create and start this QTimer::singleShot(...) and then immediately (after say 200 msec:s) return, which would "release"/"unfreeze" the menu.

However, for some reason this does not work for me. I can see that I enter sendCheckForUpdates(), pass the QTimer::singleShot(...) line with no errors and then exits sendCheckForUpdates(), but then nothing happens. I never enter checkForUpdates(). If I try to have only a direct call to checkForUpdates() from within sendCheckForUpdates(), then it works (but the menu is frozen until the task is finished).

Any ideas?

I'm using Qt 4.4.3.

yogeshgokul
9th December 2009, 13:33
Can you show the header file?

dobedidoo
10th December 2009, 07:02
Hi yogeshgokul,

I send you a personal message yesterday, with the header file. It's quite large, so not very suitable for posting here. Hope that's ok.

wagmare
10th December 2009, 07:11
use to give the timer property singleShot(true) seperatly
like this
timer->setSingleShot(TRUE);
timer->start(200);

i think the problem is that u are not starting the timer but not sure ... any how try it once ..

yogeshgokul
10th December 2009, 08:19
use to give the timer property singleShot(true) seperatly
like this
timer->setSingleShot(TRUE);
timer->start(200);

i think the problem is that u are not starting the timer but not sure ... any how try it once ..
No you doesn't need to start timer when using static member function QTimer::singleShot.

spirit
10th December 2009, 08:25
are you sure that checkForUpdates is slot?
take a look at console, maybe there are some error message or something else that can help you to solve the problem.
show us you header file.

yogeshgokul
10th December 2009, 08:36
Hi yogeshgokul,

I send you a personal message yesterday, with the header file. It's quite large, so not very suitable for posting here. Hope that's ok.

Please attach it here only so everyone can see. :)

dobedidoo
10th December 2009, 09:23
Sorry, it's all my stupidity... I realized about two hours ago that (as 'spirit' pointed out later), I had missed to make checkForUpdates a SLOT. Which of course I thought I had... So, that's all there was - a simple misstake by me. :o
It all works just fine now.

Thanks for you replies!

yogeshgokul
10th December 2009, 10:06
Sorry, it's all my stupidity... I realized about two hours ago that (as 'spirit' pointed out later), I had missed to make checkForUpdates a SLOT. Which of course I thought I had... So, that's all there was - a simple misstake by me. :o
It all works just fine now.Thanks for you replies!
Thats what we wanted to see your header :D
Anyways. :rolleyes: