Question

I have a QPushButton, QDateEdit and another custom object. I want to connect the button to the date edit object in a way that when I click the button, the date edit object will change its set date to a date defined on the custom object. Kinda like this:

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

but I can't do that. Apparently, the connect statement doesn't specify what's the information being passed from the signal to the slot, only the type of the information being passed. Is there a way to do this without having to create a new class?

Was it helpful?

Solution

It's usually easiest to create a wrapper function that contains that 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 do connect time binding with specific arguments and objects through the use of an external library called Qxt. It doesn't look like their documentation is complete or up-to-date, but they do provide some nice functionality. I consider it for advanced users only.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top