Qt - Arguments in Signal Slots

I have a QPushButton, QDateEdit and another custom object. I want to associate a button with a date editing object so that when I click the button, the date editing object will change the set date to the date defined on the user object. Kind:

connect(pushbutton,SIGNAL(clicked()),dateedit,SLOT(setDate(custom_object.getDate()))); 

but I can’t do it. Apparently, the connect operator does not indicate what information is transmitted from the signal to the slot, but only the type of information transmitted. Is there a way to do this without creating a new class?

+4
source share
1 answer

It is usually easiest to create a wrapper function containing this functionality. In other words:

 connect(pushbutton, SIGNAL(clicked()), SLOT(setDateFromCustomObject())); 

And then in the same class that calls connect:

 void YourClass::setDateFromCustomObject() { dateEdit->setDate(custom_object.getDate()); } 

It is possible to associate a time binding with specific arguments and objects using an external library called Qxt . It is not like their documentation is complete or updated, but they provide excellent functionality. I consider this only for advanced users.

+5
source

Source: https://habr.com/ru/post/1303969/


All Articles