Reputation: 535
In my custom widget, there are seven labels included as child widgets. Their texts and text formats should be set by user of the parent widget. I created 14 slots to accomplish this:
void setCenterText(const QString &text) {
ui->labelCenter->setText(text);
}
void setRightText(const QString &text);
...
Can it be done via something like: connect(parent, slot(a), child, slot(b)) and a signal connected to the parent slot is automatically forwarded to the child widget?
Upvotes: 3
Views: 250
Reputation: 22376
Can it be done via something like: connect(parent, slot(a), child, slot(b)) and a signal connected to the parent slot is automatically forwarded to the child widget?
You can't connect slots to slots, but more importantly, without specifying the target widget in another argument, there is no way for the parent widget to know which child needs modifying.
Although what you are doing is laborious, it is a basic tennant of aggregate-based component building, and it does offer advantages - primarily the ability to very finely tune exactly what child widget properties are exposed to the programmer.
Upvotes: 1