Results 1 to 8 of 8

Thread: QObject::killTimer Warning Messages

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QObject::killTimer Warning Messages

    Quote Originally Posted by mclark View Post
    What\Who is deleting the QTimer?
    Provided that the timer doesn't have a parent it has to be you or the timer is not deleted at all.
    Why is the m_pTimer value valid immediately after exec() returns but invalid when isActive() is called?
    Maybe you have a local variable somewhere that is named the same and it shadows the other variable?

    Would it be better to handle the deletion of m_pTimer in response to the QThread::finished() signal?
    No. If you create an object in run(), destroy it there. The timer won't timeout anyway after you return from exec() so there is no point in keeping it. I even suggest you change your run() a bit:

    Qt Code:
    1. void ...:run(){
    2. QTimer timer;
    3. connect(&timer, SIGNAL(timeout()), this, SLOT(checkTimestamp()));
    4. timer.start(5000);
    5. exec();
    6. // the timer will get deleted when run() returns
    7. }
    To copy to clipboard, switch view to plain text mode 

    By the way, I hope you realize the slot will be called in the context of the main thread and not the worker thread. What is the point in doing all that in a worker thread anyway? Does the thread do anything else besides running the timer?

  2. #2
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QObject::killTimer Warning Messages

    Quote Originally Posted by wysota View Post
    Provided that the timer doesn't have a parent it has to be you or the timer is not deleted at all.
    Even when I remove the 'delete m_pTimer' code the m_pTimer value changes after returning from exec(). It gets the 0xfeeefeee value. There are no other m_pTimer variables declared anywhere in this class.

    Quote Originally Posted by wysota View Post
    By the way, I hope you realize the slot will be called in the context of the main thread and not the worker thread. What is the point in doing all that in a worker thread anyway? Does the thread do anything else besides running the timer?
    The purpose of this thread is to:
    1. Maintain a list of objects. When the object is created it is put into the list. When the object is fully initialized (due to outside forces) it is removed from the list.
    2. Run the timer. When the timer times out, the list is checked. If it contains any objects that have been waiting to be initialized for too long, they are rescheduled and removed from the list. At this point the timer is restarted.

    I admit I am a novice when it comes to threading, but I don't see why the slot is run in the main threads context instead of the worker thread. The 'this' pointer in the connect() call is the worker thread pointer, no?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QObject::killTimer Warning Messages

    Quote Originally Posted by mclark View Post
    The purpose of this thread is to:
    1. Maintain a list of objects. When the object is created it is put into the list. When the object is fully initialized (due to outside forces) it is removed from the list.
    2. Run the timer. When the timer times out, the list is checked. If it contains any objects that have been waiting to be initialized for too long, they are rescheduled and removed from the list. At this point the timer is restarted.
    You don't need a separate thread for that.

    I admit I am a novice when it comes to threading, but I don't see why the slot is run in the main threads context instead of the worker thread. The 'this' pointer in the connect() call is the worker thread pointer, no?
    No, it is a pointer to an object representing the thread. And the object itself lives in the context of the thread that created it (the object, not the thread) therefore it lives in context of the main thread.

  4. The following user says thank you to wysota for this useful post:

    mclark (11th September 2008)

Similar Threads

  1. Visual Studio 2005 Express
    By Muzz in forum Installation and Deployment
    Replies: 22
    Last Post: 6th November 2008, 06:21
  2. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  3. Crash handler on Win32
    By niko in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 19:41
  4. Problem at time compilation in traslation of language
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2007, 14:18
  5. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23

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.