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:
Qt Code:
  1. class ConfigWidget : public QWidget
  2. {
  3. public:
  4. explicit ConfigWidget(QWidget *parent = 0) : QWidget(parent){}
  5. virtual void SetValues(){}
  6. virtual void SaveValues(){}
  7. };
To copy to clipboard, switch view to plain text mode 
And the code of accept() signal of this dialog:
Qt Code:
  1. void ConfigDialog::okClicked()
  2. {
  3. QList<ConfigWidget *> widgets = findChildren<ConfigWidget *>();
  4. foreach(ConfigWidget * widget,widgets)
  5. {
  6. widget->SaveValues();
  7. }
  8. Config::instance()->SaveConfig();
  9. accept();
  10. }
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?