Hii
How can I use a Slot with an argument whenever a push button is clicked
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
Qt Code:
connect(pushButton, SIGNAL(clicked ( bool),this, SLOT(slot(bool));To copy to clipboard, switch view to plain text mode
Cheers,
Phillip
--- Please post the solution you got to solve your problem. It may help others.
I want to pass a pointer of a class to the slot not bool or some other type
Then you'll need to create your own SLOT and SIGNAL.
eg.
Qt Code:
void mySignal(myClass *c);To copy to clipboard, switch view to plain text mode
and then
Qt Code:
emit mySignal(myClassPtr);To copy to clipboard, switch view to plain text mode
in your click slot.
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.
It's nice to be important but it's more important to be nice.
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:
this actually won't work, i don't know why i can't use it like that. i also tried:Qt Code:
connect(ui_package.pb_ok,SIGNAL(clicked()),this,SLOT(dia_package.accept()));To copy to clipboard, switch view to plain text mode
wasn't a good idea either, so i thought of creating a method which closes the dialogs for me, so i wrote this:Qt Code:
connect(ui_package.pb_ok,SIGNAL(clicked()),dia_package,SLOT(accept()));To copy to clipboard, switch view to plain text mode
Qt Code:
d->accept(); }To copy to clipboard, switch view to plain text modebut 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?Qt Code:
connect(ui_package.pb_ok,SIGNAL(clicked()),this,SLOT(close_dialog(dia_package)));To copy to clipboard, switch view to plain text mode
thx
tobi
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.
It's nice to be important but it's more important to be nice.
ok,
the error is:
Qt Code:
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*)'To copy to clipboard, switch view to plain text mode
and i can't use autocomplete in SLOT(), little wired![]()
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.
It's nice to be important but it's more important to be nice.
T0bi4s (8th December 2009)
thx mr axel jägernow it works
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
The arguments of signals and slots are types, not variables.
You passed t which is a variable and not a type.
It's nice to be important but it's more important to be nice.
Thank a lot.
Bookmarks