MyClass1 *my = qobject_cast <MyClass1*> (ptr);Q_CHECK_PTR (my);
QObject *obj = new MyClass(a,b,c,d);MyClass *cls = (MyClass*)obj;
char* name1 = ptr->staticMetaObject()->className();if (name1 == 'MyClass1'){ MyClass1 *my = qobject_cast <MyClass1*> (ptr); ...}if (name1 == 'MyClass2'){ MyClass2 *my = qobject_cast <MyClass2*> (ptr); ...}
MyClass *my = qobject_cast <MyClass*> (ptr); if (my) my.MyAbstractMethod();
C++ (Qt)void MyClass::setButtonsInactive(QWidget* wgt=0){ if (!wgt) wgt = this; // Бывает )) for (int i=0; i<wgt->children().size(); ++i) { QPushButton* trybutton = qobject_cast <QPushButton*> (wgt->children().at(i)); if (trybutton) {trybutton->setEnabled(false); continue;} QWidget* tryWidget = qobject_cast <QWidget*> (wgt->children().at(i)); if (tryWidget) {setButtonsInactive(tryWidget);} }}
C++ (Qt)void MyClass.setButtonsInactive(QWidget* wgt=this)