QTimer::singleShot - forward parameter to SLOT called
-
@McLion: You are right. I forgot the (): [] () {MySlot(0); }
It's the lambda function of C++11. -
Ancient compiler and/or Qt version I guess. You can use QSignalMapper then:
QSignalMapper* idMapper= new QSignalMapper(this) connect(idMapper,SIGNAL(mapped(int)),this,SLOT(MySlot(int))); for (int iId=0; iId < 2; ++iId){ QTimer* tempTimer=new tempTimer(this); tempTimer->setInterval(5000); tempTimer->setSingleShot(true); idMapper->setMapping(tempTimer, iId); connect(tempTimer,SIGNAL(timeout()),idMapper,SLOT(map())); connect(tempTimer,SIGNAL(timeout()),tempTimer,SLOT(deleteLater())); tempTimer->start(); }
-
Ancient compiler and/or Qt version I guess. You can use QSignalMapper then:
QSignalMapper* idMapper= new QSignalMapper(this) connect(idMapper,SIGNAL(mapped(int)),this,SLOT(MySlot(int))); for (int iId=0; iId < 2; ++iId){ QTimer* tempTimer=new tempTimer(this); tempTimer->setInterval(5000); tempTimer->setSingleShot(true); idMapper->setMapping(tempTimer, iId); connect(tempTimer,SIGNAL(timeout()),idMapper,SLOT(map())); connect(tempTimer,SIGNAL(timeout()),tempTimer,SLOT(deleteLater())); tempTimer->start(); }
-
@VRonin
Thanks!
any idea why it builds ok but crashes on this line?
iGUIidMapper->setMapping(tempTimer, iGUIid);
-
@McLion In all probability because either
tempTimer
oriGUIidMapper
are rouge pointers. Can you show us the rest of the code?@VRonin
in constructor:QSignalMapper* iGUIidMapper = new QSignalMapper(this); connect(iGUIidMapper, SIGNAL(mapped(int)), this, SLOT(HandleGUIloadTimeOut(int)));
.. and in function ..
void QTGUI_MainWindow::HandleGUIloadTimeOut(int iGUIid) { static uint iIsRunning = 0; if(iIsRunning & (0x01 << iGUIid)) { iIsRunning &= ~(0x01 << iGUIid); webGUI_loadFinished(false); } else { iIsRunning |= (0x01 << iGUIid); QTimer* tempTimer = new QTimer(this); tempTimer->setInterval(5000); tempTimer->setSingleShot(true); GUIidMapper->setMapping(tempTimer, iGUIid); connect(tempTimer, SIGNAL(timeout()), GUIidMapper, SLOT(map())); connect(tempTimer, SIGNAL(timeout()), tempTimer, SLOT(deleteLater())); tempTimer->start(); } }
-
You use
QSignalMapper* iGUIidMapper
in the contructor, so the variableiGUIidMapper
is unknown outside of the contructor. -
@McLion: In the constructor you set the variable (locally) declared in the contructor, but the member variable declared in *.h is still unset.
-
btw I don't think I like what you are doing with
iIsRunning
I think it shouldn't be static (different windows should use differentiIsRunning
) and it's unnecessarily limited (ifiGUIid >31
you have a problem). aQSet<int>
to store theiGUIid
is much more flexible -
btw I don't think I like what you are doing with
iIsRunning
I think it shouldn't be static (different windows should use differentiIsRunning
) and it's unnecessarily limited (ifiGUIid >31
you have a problem). aQSet<int>
to store theiGUIid
is much more flexible