PDA

View Full Version : timeout() signal to a slot with arguments



sujan.dasmahapatra
11th June 2010, 14:19
Dear Friends

I am trying to connect timeout() signal to a slot updateJobStatus(long ID), This updateJobStatus(long ID) should take an argument. If I dont put any argument in the function then its working fine. If I put arguments in the slot then its not working, check the code snippet below.

int jobID=34343;
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(updateJo bStatus(jobID)));
timer->start(1000);

Now this updateJobStatus basically displays the ID on a regular interval.

But when I execute this program I can see
Object::connect: No such slot MainWindow::updateJobStatus(jobID) in src/mainwindow.cpp:1903

is it not possible to declare arguments in the solt. I am having some doubts in this
Can anyone clear my doubts. Thanks in advance.sujan

Lesiok
11th June 2010, 14:42
Read about signal mappers (http://doc.trolltech.com/4.6/qsignalmapper.html#details)

amoswood
11th June 2010, 14:46
No, it is not possible to declare arguments in a slot using the connect function. For signals/slots, the argument list of the slot must be the same arguments or fewer than the signal. Otherwise, their isn't a value passed to the slot.

Don't fret though, for your usage Qt DOES have a way around this though using the class QSignalMapper.

Good luck!

borisbn
11th June 2010, 14:48
You can use 3-rd party classes, such as libqxt's QxtTimer (http://doc.libqxt.org/0.6.0/qxttimer.html)