In my program I have QDialog to edit configuration options and it is empty as program start.
I use QPlugin modules so each module can add its own panel to this dialog. Base class of such panel is:
class ConfigWidget
: public QWidget{
public:
virtual void SetValues(){}
virtual void SaveValues(){}
};
class ConfigWidget : public QWidget
{
public:
explicit ConfigWidget(QWidget *parent = 0) : QWidget(parent){}
virtual void SetValues(){}
virtual void SaveValues(){}
};
To copy to clipboard, switch view to plain text mode
And the code of accept() signal of this dialog:
void ConfigDialog::okClicked()
{
QList<ConfigWidget *> widgets = findChildren<ConfigWidget *>();
foreach(ConfigWidget * widget,widgets)
{
widget->SaveValues();
}
Config::instance()->SaveConfig();
accept();
}
void ConfigDialog::okClicked()
{
QList<ConfigWidget *> widgets = findChildren<ConfigWidget *>();
foreach(ConfigWidget * widget,widgets)
{
widget->SaveValues();
}
Config::instance()->SaveConfig();
accept();
}
To copy to clipboard, switch view to plain text mode
I just get all the panels and save its values. I guess it is very simple and clear.
But findChildren returns all the widgets of dialog - buttons, lineedits etc. And it is very very strange for me.
From docs: Returns all children of this object with the given name that can be cast to type T
How QPushButton can be cast to ConfigWidget?? QPushButton have no SaveValues() function so I am very disappointed here ...
And, if it is expected result of findChildren(), how can I get only widgets derived from ConfigWidget?
Bookmarks