Results 1 to 9 of 9

Thread: QTimer::singleShot(...) triggered from a QAction does not start!?

  1. #1
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    34
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Question QTimer::singleShot(...) triggered from a QAction does not start!?

    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:
    Qt Code:
    1. void MainWindow::sendCheckForUpdates()
    2. {
    3. QTimer::singleShot(200, this, SLOT(checkForUpdates()));
    4. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTimer::singleShot(...) triggered from a QAction does not start!?

    Can you show the header file?

  3. #3
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    34
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTimer::singleShot(...) triggered from a QAction does not start!?

    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.

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTimer::singleShot(...) triggered from a QAction does not start!?

    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 ..
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTimer::singleShot(...) triggered from a QAction does not start!?

    Quote Originally Posted by wagmare View Post
    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.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTimer::singleShot(...) triggered from a QAction does not start!?

    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.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTimer::singleShot(...) triggered from a QAction does not start!?

    Quote Originally Posted by dobedidoo View Post
    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.

  8. #8
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    34
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Red face Re: QTimer::singleShot(...) triggered from a QAction does not start!?

    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.
    It all works just fine now.

    Thanks for you replies!

  9. #9
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTimer::singleShot(...) triggered from a QAction does not start!?

    Quote Originally Posted by dobedidoo View Post
    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.
    It all works just fine now.Thanks for you replies!
    Thats what we wanted to see your header
    Anyways.

Similar Threads

  1. Replies: 2
    Last Post: 27th February 2007, 21:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.