QTimer::singleShot - forward parameter to SLOT called
Solved
General and Desktop
-
Hi
I'd like to do something like this:
QTimer::singleShot(5000, this, SLOT(MySlot(iID)));
to get the ID (can be 1 to 16) and know which ID did kick off the singleShot.
However, that seems not to be possible with on-board tools.Any idea how this can be easily implemented?
Thanks
McL -
Hi,
how aboutQTimer::singleShot(5000, this, [] () {MySlot(0); }); QTimer::singleShot(5000, this, [] () {MySlot(1); });
etc. or
for (iId=0; iId < 2; ++iId) QTimer::singleShot(5000, this, [iId] () {MySlot(iId); });
if you want to keep the variable.
-Michael. -
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
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(); } }
-
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