开发者

Qt - arguments in signal-slots

I have a QPushButton, QDateEdit and another custom object. I want to connect the b开发者_JAVA百科utton 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜