Results 1 to 3 of 3

Thread: Strange inconsistency with QTimer

  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 03:39.

  2. #2

    Default Re: Strange inconsistency with QTimer

    I'm having some weird bugs with this program. I edited the configuration file, only leaving one widget in the layout, and the program complained that the definition for that widget didn't exist. Then I commented them all out but the last one, and it finds the definition fine. Weird. But that's not why I'm updating this. The timer for that single widget never fires at all. I call timer_->start() but it never fires.

    Here's how I initialize the timer.

    Qt Code:
    1. timer_ = new QTimer();
    2. timer_->setSingleShot(false);
    3. timer_->setInterval(update_->P2INT());
    4. QObject::connect(timer_, SIGNAL(timeout()), this, SLOT(Update()));
    To copy to clipboard, switch view to plain text mode 

  3. #3

    Default Re: Strange inconsistency with QTimer

    I figured this out.

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 12:51
  2. Extending QTimer()
    By rishid in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2009, 02:59
  3. QThread/QObject and QTimer
    By swiety in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2008, 09:37
  4. Replies: 5
    Last Post: 6th March 2007, 06:34
  5. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 13: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.