Results 1 to 10 of 10

Thread: QTimer in QThread doesn't start or timeout

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2
    Thanked 29 Times in 28 Posts

    Default Re: QTimer in QThread doesn't start or timeout

    No. Timer creation has to be done in run(). If only connect() is done in run() it doesn't work.

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 66 Times in 62 Posts

    Default Re: QTimer in QThread doesn't start or timeout

    hmm..this whole situation is definitely a bit weird..cuz the documentation should mention that any kind of initialization done in the constructor would not take any effect when the thread is actually run..and although it makes sense that run method should have all the initialization, one can always make a mistake of initializing in constructor being a C++ developer....any guru thoughts on this?

  3. #3
    Join Date
    Jul 2010
    Location
    Fortaleza, Brazil
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTimer in QThread doesn't start or timeout

    I don't know if you sove that, but that maybe help others.

    Call in class constructor:
    this->moveToThread(this);
    countTimer->moveToThread(this);

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: QTimer in QThread doesn't start or timeout


    Added after 4 minutes:

    hmm..this whole situation is definitely a bit weird..cuz the documentation should mention that any kind of initialization done in the constructor would not take any effect when the thread is actually run..and although it makes sense that run method should have all the initialization, one can always make a mistake of initializing in constructor being a C++ developer....any guru thoughts on this?
    this is because what you code you do in constructor is done in the calling thread. The code in run will be executed in the new thread after start() is called. timers dont work well across thread boundaries so you either need to instantiate the timer in run() or use moveTothread() in run to move the timer.

    Quote Originally Posted by israelins View Post
    I don't know if you sove that, but that maybe help others.

    Call in class constructor:
    this->moveToThread(this);
    countTimer->moveToThread(this);
    that is ridiculous :-/
    Last edited by amleto; 21st October 2011 at 14:49.

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 12:51
  2. QTimer and QThread in Qtopia 4.2.0
    By mellibra in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 25th October 2007, 09:26
  3. QThread : run() Vs start()
    By cs_raja in forum Qt Programming
    Replies: 4
    Last Post: 21st November 2006, 11:36
  4. QTimer and QThread
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 21st September 2006, 15:52
  5. Replies: 6
    Last Post: 17th March 2006, 18:48

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
  •  
Qt is a trademark of The Qt Company.