Results 1 to 3 of 3

Thread: Strange inconsistency with QTimer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Strange inconsistency with QTimer

    Maybe the map is getting corrupted. But I'm getting some real inconsistencies with the following code. I've explained in comments. Basically, there's a QTimer set to singleShot=false, meaning it should fire over and over at every interval milliseconds. Well, I only want one widget to update the special chars. All Gif widgets with the same widget_base (That's the name of the widget in the config file: such as widget_american_flag) use the same special chars, so only one needs to update those special chars. Well, if I allow the program to have all widget_base widgets to update, it runs fine, but if I limit it to one only, the timer for that widget only shoots off once. Really weird bug.

    First, where WidgetGif::Start() is called:

    Qt Code:
    1. template <class T>
    2. void Generic<T>::StartLayout() {
    3. std::string key;
    4. gen(current_layout_);
    5. Error("StartLayout: %s", key.c_str());
    6.  
    7. emit static_cast<LCDEvents *>(wrapper_)->_LayoutChangeBefore();
    8. std::map<std::string, Widget *> widgets = widgets_;
    9. for(std::map<std::string,Widget *>::iterator w = widgets.begin();
    10. w != widgets.end(); w++){
    11.  
    12. if(current_layout_ != w->second->GetLayoutBase() )
    13. continue;
    14.  
    15. if( type_ == LCD_TEXT &&
    16. (w->second->GetType() & WIDGET_TYPE_SPECIAL)) {
    17. w->second->SetupChars();
    18. }
    19.  
    20. w->second->Start();
    21. }
    22. emit static_cast<LCDEvents *>(wrapper_)->_LayoutChangeAfter();
    23. std::stringstream strm;
    24. std::string str;
    25. strm << current_layout_ << ".timeout";
    26. strm >> str;
    27. Json::Value *timeout = CFG_Fetch(CFG_Get_Root(), str,
    28. new Json::Value(layout_timeout_));
    29. timer_->start(timeout->asInt());
    30. Error("timeout: %d", timeout->asInt());
    31. delete timeout;
    32. }
    To copy to clipboard, switch view to plain text mode 

    Now WidgetGif::Start()

    Qt Code:
    1. template <class T>
    2. void WidgetGif<T>::Start() {
    3. if(is_started_)
    4. return;
    5. if(update_->P2INT() < 0)
    6. return;
    7. if(!has_chars_) {
    8. Update(); // This does not crash the program unlike the one call to Update() below.
    9. Error("Not Starting widget: %s", name_.c_str());
    10. return; // If I comment this out, all widgets' timers update fine.
    11. }
    12. Error("Starting widget: %s", name_.c_str());
    13. timer_->start(); // Only shoots off once if only one widget got this far. (widget_american_flag:0 in this case)
    14. //Update(); // Uncommenting this causes a crash.. something about RB_trees related to the map in StartLayout.
    15. is_started_ = true;
    16. }
    To copy to clipboard, switch view to plain text mode 

    Edit: I changed the code a bit and found that one widget (widget_american_flag:0) never fires even when I allow them all to have running timers.
    Last edited by starlon; 23rd October 2009 at 02:39.

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. Extending QTimer()
    By rishid in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2009, 01:59
  3. QThread/QObject and QTimer
    By swiety in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2008, 08:37
  4. Replies: 5
    Last Post: 6th March 2007, 05:34
  5. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54

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.