Qtimer singleshot not working
-
wBIT w; w.setGeometry(0, 0, defineSize.width(), defineSize.height()); w.show(); QTimer::singleShot(1500, &w, SLOT(w.StopTest(false))); void wBIT::StopTest(bool bStop) { this->ui.wBitItem_Device->ProcessCheck(bStop); this->ui.wBitItem_WMotor->ProcessCheck(bStop); this->ui.wBitItem_CMotor->ProcessCheck(bStop); this->ui.wBitItem_FMotor->ProcessCheck(bStop); this->ui.wBitItem_LMotor->ProcessCheck(bStop); this->ui.wBitItem_TLamp ->ProcessCheck(bStop); this->ui.wBitItem_DLamp ->ProcessCheck(bStop); this->ui.wBitItem_DPeak ->ProcessCheck(bStop); }
I want to send a stop signal after 1,500 milliseconds, but it doesn't work.
-
@IknowQT said in Qtimer singleshot not working:
SLOT(w.StopTest(false)));
This is wrong and you will also get a runtime warning on your console about this. If you want to pass a variable use the new signal/slot syntax with a lambda or call another slot which then calls the real function with your parameter.
-
@IknowQT said in Qtimer singleshot not working:
wBIT w;
This again...
You are declaring a local variable, which gets out of scope and is deleted.
Either allocate it on the heap or make it class member... -
@IknowQT said in Qtimer singleshot not working:
SLOT(w.StopTest(false)));
This is wrong and you will also get a runtime warning on your console about this. If you want to pass a variable use the new signal/slot syntax with a lambda or call another slot which then calls the real function with your parameter.
-
@IknowQT said in Qtimer singleshot not working:
SLOT(w.StopTest(false))
this
SLOT(w.StopTest(false))
is 100% wrong, you can't set arguments in SLOT macro