Hii
How can I use a Slot with an argument whenever a push button is clicked
Printable View
Hii
How can I use a Slot with an argument whenever a push button is clicked
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.
Code:
void mySignal(myClass *c);
and then
Code:
emit mySignal(myClassPtr);
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.
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:Code:
connect(ui_package.pb_ok,SIGNAL(clicked()),this,SLOT(dia_package.accept()));
wasn't a good idea either, so i thought of creating a method which closes the dialogs for me, so i wrote this:Code:
connect(ui_package.pb_ok,SIGNAL(clicked()),dia_package,SLOT(accept()));
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?Code:
connect(ui_package.pb_ok,SIGNAL(clicked()),this,SLOT(close_dialog(dia_package)));
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.
ok,
the error is:
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*)'
and i can't use autocomplete in SLOT(), little wired:confused:
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.
thx mr axel jäger :D now 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.
Thank a lot.