QWidget window fails to open when "SetParent" is not null
My program displays a main window object when launched. On that window is a QPushButton control that should open a dialog window. When the below code executes though, nothing happens. After playing for a few minutes, I found that the problem occurs when "setParent" is executed. As long as that line is commented out, the code works fine. Once I uncomment it, the window fails to open.
Any idea of what I'm doing wrong?
cityDialogWindow = new cityDialog;
cityDialogWindow->setParent( this );
What type of widget does "this" refer to?
Oops. My apologies. The main window object also inherits from QWidget. I've put the class header below. It's nothing fancy.
class mainWindow : public QWidget
QPushButton *quitButton; QPushButton *nextTurnButton; QPushButton *showCityDialog; QPushButton *createButton(QString caption); QHBoxLayout *mainLayout; graphicsHelper helper;
The usual way is to pass the parent widget in the constructor:
// change your constructor declaration to
mainWindow(QWidget *parent = 0);
// change your constructor defintion to
mainWindow::mainWindow(QWidget *parent) : QWidget(parent)
// and construct your object this way:
cityDialogWindow = new mainWindow(this);