Results 1 to 10 of 10

Thread: Problem with QObject::timerEvent()

  1. #1
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem with QObject::timerEvent()

    Using Qt 4.5.0 Open Source under Windwos Vista 64 - I am having a problem with timerEvent().

    I start timers in my QObject derived class:

    timer_ID_t item_timer_id = startTimer( FadeTimerInterval );
    if ( item_timer_id != 0 )
    {
    acivity_timer_map_[ item_timer_id ] = item;
    }

    timer_ID_t is a typedef of int
    FadeTimerInterval is a static const int whose value is 50
    acivity_timer_map_ is a std::map<>

    This is done twice and I get back timer IDs of 5 and 6.
    But in the timerEvent( QTimerEvent* ev ) that
    gets called ev->timerId() returns 4 every time.

    Is this a deprecated timer event method? Does Qt coalesce timers if the same object starts multiple timers?

  2. #2
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QObject::timerEvent()

    Just in case it turns out I can't use timer events in this way let me describe what I am trying to do and ask some related questions.

    I am making a networking app. One of the features is a list of entities out on the network that are transmitting to this machine. I am using a QTreeView to implement a multi-column list view. In one column I wanted to have pixmaps of LEDs that will light up when network activity happens.

    I have implemented the custom drawing of items in the LED column using the StarDelegate example as a guide. That works fine. I am now trying to implement a way to have a fade timer.

    Network activity causes things to happen that end up in a pixmap representing a lit LED to be displayed but I want to be able to fade it to off over a time interval.

    I want to be as efficient with this as possible. As a side issue I wondered if there was some info on how the paint system works from Qt's point of view. For example: in windows I would probably be invalidating the rectangles of the LED pixmaps that were affected but I can't find any info analogous to this in Qt. So I am just going to rely on dataChanged signals from the affected items.

    Because I want the fade to happen gradually over a time period I went with a timer event for each entity in the list. I would have used a single timer event and update everyone but I can't find anything analogous to a tick count - So I could store a tick count in each item when the light goes on and on each timer event see how long the current tick count is from the count when the on state occurred in order to scale the brightness. Querying the Date/Time seems a little inefficient for what I want to do. I may be wrong.

    Well, if it turns out that I need a separate QTimer for each LED fade - I notice that in the posts about QTimer I always seem code fragments like the following:

    MyObject::MyObject()
    {
    QTimer* my_timer = new QTimer( this );

    // connect signals/slots, set intervals, start...
    }

    This is a memory leak right? Is it just this way for brevity? Or is there some memory management Qt does to reclaim the memory when the timer is killed? I see this form again and again in code people are posting for questions on their own projects.

    Thanks in advance.

  3. #3
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: Problem with QObject::timerEvent()

    OK found my problem. The timer start was done in the thread that monitors the network, not the GUI thread. QObject::startTimer should have returned 0 so I knew the was a problem. I only found out by tracing into the code.

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

    Default Re: Problem with QObject::timerEvent()

    Did you have the console support enabled? Qt should have warned you there that you were doing something you were not supposed to.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QObject::timerEvent()

    Good question. I guess that would be how I would get to see all the debug messages I see in the source code but didn't know how to have Qt display.

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

    Default Re: Problem with QObject::timerEvent()

    Just add "CONFIG+=console" to your qmake project and rerun qmake.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QObject::timerEvent()

    Ah that's it - I'm using MSVC 2005.

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

    Default Re: Problem with QObject::timerEvent()

    You can still add it to the project and regenerate the VS project using qmake. Or you can enable the console subsystem directly in VS.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QObject::timerEvent()

    I just remembered about enabling the console subsystem. Had stopped running my app that way for aesthetic reasons.

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

    Default Re: Problem with QObject::timerEvent()

    This is useful only for debugging. When you release it to your users, disable the console.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 23rd April 2009, 09:05
  2. Replies: 19
    Last Post: 3rd April 2009, 23:17
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Tags for this Thread

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.