PDA

View Full Version : QTimer::singleshot doesn't call SLOTs with arguments



hulk
6th April 2006, 13:19
hi all,

I want to execute my function "saveTraining()" 20 seconds after another function. I suppose a SingleShot-Timer to be the right choice.

If I call this command


QTimer::singleShot( 20000, this, SLOT(saveTraining()));

my function "saveTraining()" is executed properly after 20 seconds. All works fine.

But if I try to commit an argument like in this command:


QTimer::singleShot( 20000, this, SLOT(saveTraining(5)));

my function "saveTraining(int number)" isn't executed.


Infos:
-I also tried to commit other arguments, like QString or QPointF without success.
-The compiler is compiling this project without any errors or warnings
-There is the right prototyp of my function in the .h-File
-I also tried to commit a "Klassenvariable" without success. I don't know the right english word for "Klassenvariable". It's a variable which is declared staticly in the class so that every object of this class has this variable. Maybe "membervariable" is the right word for it.
-Version Qt 4.1.2 Open Source


Where is my mistake? Could it be possible that it isn't allowed to commit arguments in a SingleShot-Timer? I didn't see such an info in the documentation. I hope you can help me. Sorry for my probably bad english.

Hulk

jpn
6th April 2006, 13:24
You cannot put parameter values to signals and slots (http://doc.trolltech.com/4.1/signalsandslots.html) in the connect statement.
You can only put parameter types, which need to match exactly for the signal and the slot (exception: a slot can have less parameters than the signal..)

If you want one timer to emit some value and another timer to emit some different value, you can use a QSignalMapper (http://doc.trolltech.com/4.1/qsignalmapper.html).