You need signals and slots.
You need to connect the selected signal to the user slot you created in the main widget.
Corrected code based on comments by Patrice Bernassola and Job .
In the class definition (.h file) add the lines:
Q_OBJECT private slots: void exampleButtonClicked(); private: QDialog *exampleDialog;
The Q_OBJECT macro is needed when you define signals or slots in your classes.
The variable exampleDialog must be declared in the definition file in order to access it in the slot.
And you should initialize it, this is usually done in the constructor
ExampleClass::ExampleClass() {
In the class implementation (.cpp file) add code that does what you want, in this case create a new window.
void ExampleClass::exampleButtonClicked() { exampleDialog->show(); }
And also you must connect the signal to the slot using the line:
connect(exampleButton, SIGNAL(clicked()), this, SLOT(exampleButtonClicked()));
Your question is basic, so I suggest reading a basic tutorial, so you can make progress faster by avoiding the expectation of answers. Some links to tutorials that were useful to me:
http://zetcode.com/tutorials/qt4tutorial/
http://doc.qt.io/archives/qt-4.7/tutorials-addressbook.html