PDA

View Full Version : Strange inconsistency with QTimer



starlon
23rd October 2009, 02:33
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:



template <class T>
void Generic<T>::StartLayout() {
std::string key;
gen(current_layout_);
Error("StartLayout: %s", key.c_str());

emit static_cast<LCDEvents *>(wrapper_)->_LayoutChangeBefore();
std::map<std::string, Widget *> widgets = widgets_;
for(std::map<std::string,Widget *>::iterator w = widgets.begin();
w != widgets.end(); w++){

if(current_layout_ != w->second->GetLayoutBase() )
continue;

if( type_ == LCD_TEXT &&
(w->second->GetType() & WIDGET_TYPE_SPECIAL)) {
w->second->SetupChars();
}

w->second->Start();
}
emit static_cast<LCDEvents *>(wrapper_)->_LayoutChangeAfter();
std::stringstream strm;
std::string str;
strm << current_layout_ << ".timeout";
strm >> str;
Json::Value *timeout = CFG_Fetch(CFG_Get_Root(), str,
new Json::Value(layout_timeout_));
timer_->start(timeout->asInt());
Error("timeout: %d", timeout->asInt());
delete timeout;
}


Now WidgetGif::Start()



template <class T>
void WidgetGif<T>::Start() {
if(is_started_)
return;
if(update_->P2INT() < 0)
return;
if(!has_chars_) {
Update(); // This does not crash the program unlike the one call to Update() below.
Error("Not Starting widget: %s", name_.c_str());
return; // If I comment this out, all widgets' timers update fine.
}
Error("Starting widget: %s", name_.c_str());
timer_->start(); // Only shoots off once if only one widget got this far. (widget_american_flag:0 in this case)
//Update(); // Uncommenting this causes a crash.. something about RB_trees related to the map in StartLayout.
is_started_ = true;
}



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.

starlon
23rd October 2009, 03:15
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.



timer_ = new QTimer();
timer_->setSingleShot(false);
timer_->setInterval(update_->P2INT());
QObject::connect(timer_, SIGNAL(timeout()), this, SLOT(Update()));

starlon
23rd October 2009, 06:57
I figured this out.