Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget window fails to open when "SetParent" is not null
QtWS25 Last Chance

QWidget window fails to open when "SetParent" is not null

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cazador7907
    wrote on last edited by
    #1

    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 );
    cityDialogWindow->show();
    @

    Laurence -

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      What type of widget does "this" refer to?

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cazador7907
        wrote on last edited by
        #3

        Oops. My apologies. The main window object also inherits from QWidget. I've put the class header below. It's nothing fancy.

        @
        #include <InterfaceWidgets/gameturnwidget.h>
        #include <InterfaceWidgets/economywidget.h>
        #include <InterfaceWidgets/citydialog.h>
        #include <Helper/graphicshelper.h>
        #include <QHBoxLayout>
        #include <QVBoxLayout>
        #include <QString>
        #include <QPushButton>

        class mainWindow : public QWidget
        {
        Q_OBJECT

        public:
        mainWindow();

        private:
        gameTurnWidget *gameTurn;
        economyWidget *economyInfo;
        cityDialog *cityDialogWindow;

        QPushButton *quitButton;
        QPushButton *nextTurnButton;
        QPushButton *showCityDialog;
        
        QPushButton *createButton(QString caption);
        
        QHBoxLayout *mainLayout;
        graphicsHelper helper;
        

        public slots:
        void showCityWindow();

        };

        @

        Laurence -

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          The usual way is to pass the parent widget in the constructor:

          @
          // change your constructor declaration to

          public:
          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);
          @

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved