View Full Version : Signal and slot
jayreddy
7th December 2009, 12:27
Hii
How can I use a Slot with an argument whenever a push button is clicked
phillip_Qt
7th December 2009, 12:37
Hii
How can I use a Slot with an argument whenever a push button is clicked
And what is the argument u r passing in Slot.? if it is bool, then u can use like
connect(pushButton, SIGNAL(clicked ( bool),this, SLOT(slot(bool));
jayreddy
7th December 2009, 12:40
I want to pass a pointer of a class to the slot not bool or some other type
squidge
7th December 2009, 13:11
Then you'll need to create your own SLOT and SIGNAL.
eg.
void mySignal(myClass *c);
and then
emit mySignal(myClassPtr);
in your click slot.
axeljaeger
7th December 2009, 13:25
There is big chance that you want to do something strange. Please explain what you want to do and we will help you how to map that to the Qt-way.
Anyway, if you want to get the sender object, check the sender()-function in your slot.
But be warned again: There is only rare cases where this is a good idea and I doubt that you hit one of these.
T0bi4s
8th December 2009, 13:26
hi :),
got somehow a similar problem:
my programm should calculate how to place packages on a stack, therefore i created a main_acting_class which actually contains all needed functions, anyway to enter values i got some dialogs and i want to close them, but i can't connect the signals.
I'll show what i mean:
connect(ui_package.pb_ok,SIGNAL(clicked()),this,SL OT(dia_package.accept()));
this actually won't work, i don't know why i can't use it like that. i also tried:
connect(ui_package.pb_ok,SIGNAL(clicked()),dia_pac kage,SLOT(accept()));
wasn't a good idea either, so i thought of creating a method which closes the dialogs for me, so i wrote this:
void acting_class::close_dialog(QDialog* d){
d->accept();
}
connect(ui_package.pb_ok,SIGNAL(clicked()),this,SL OT(close_dialog(dia_package)));
but i guess d is in this case no pointer like in c#, so anyone got an idea what i could do about this little problem?
thx
tobi
axeljaeger
8th December 2009, 13:29
The second attempt should work and is the way it is supposed to work. Please provide more info what was not working there.
Indeed d IS a pointer.
T0bi4s
8th December 2009, 13:37
ok,
the error is:
C:/Users/Tobias/Desktop/Schule/AINF/Diplomarbeit/New01/acting_class.cpp:20: error: no matching function for call to 'acting_class::connect(QPushButton*&, const char*, QDialog&, const char*)'
and i can't use autocomplete in SLOT(), little wired:confused:
axeljaeger
8th December 2009, 13:39
The receiver object has to be a pointer to a QObject. Prepend the receiver with & to take the adress of the object and converting object to pointer.
T0bi4s
8th December 2009, 13:44
thx mr axel jäger :D now it works
jayreddy
14th December 2009, 10:00
hii..
Even I did the same what you did, passing a pointer of a class as an argument to the slot.
my own class lineedit..
lineedit *t ;
connect (t->temp, SIGNAL(clicked()), this, SLOT(del_tag1(t)));
(temp is pushbutton defined in that class)
But an error saying
Object::connect: No such slot QOlaiTagsWidget::del_tag1(t)
is displaying.
Can you help me regarding this .
Thank You
axeljaeger
14th December 2009, 12:59
The arguments of signals and slots are types, not variables.
You passed t which is a variable and not a type.
jayreddy
15th December 2009, 05:05
Thank a lot.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.