Skip to content

Instantly share code, notes, and snippets.

@j2doll
Created January 16, 2018 07:50
Show Gist options
  • Select an option

  • Save j2doll/74358f7539aa6e68e6922ab5bceb7907 to your computer and use it in GitHub Desktop.

Select an option

Save j2doll/74358f7539aa6e68e6922ab5bceb7907 to your computer and use it in GitHub Desktop.
Qt MOC sample #1
// class MyWidget : public QWidget
QObject *obj = new MyWidget;
QWidget *widget = qobject_cast<QWidget *>(obj);
Q_ASSERT( widget != NULL );
MyWidget *myWidget = qobject_cast<MyWidget *>(obj);
Q_ASSERT( myWidget != NULL );
QLabel *label = qobject_cast<QLabel *>(obj);
Q_ASSERT( label != NULL ); // label is 0(NULL). because obj is not inherited from QLabel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment