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. Creating new window understanding question
Forum Updated to NodeBB v4.3 + New Features

Creating new window understanding question

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.6k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jankoh
    wrote on last edited by
    #1

    Hi there,

    I have a problem creating a new window from an existing one (this is most probably a dumb newbie question). I have the following code:

    qBandHelper.cpp
    @
    qBandHelper::qBandHelper(QWidget *parent)
    {
    Ui_qBandHelper::setupUi(this);

    connect(action_Members, SIGNAL( triggered() ), this, SLOT( showMemberDialog() ) );
    

    }

    void qBandHelper::showMemberDialog( void )
    {
    QDialog *dlg = new QDialog;
    qBandMembers *memb = new qBandMembers(dlg);

    memb->show();
    

    }
    @

    qBandMembers.cpp
    @
    qBandMembers::qBandMembers(QDialog *dlg)
    {
    Ui_Members::setupUi(dlg);

    connect(qBandMembers::buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );
    connect(qBandMembers::buttonBox, SIGNAL(accepted()), this, SLOT(save()) );
    

    }
    @

    (this is only the relevant parts, of course). The qBandMembers class inherits from the qBandHelper class, but thats not relevant to the problem I have:

    If I klick the button for the member window, I get a copy of the original window (not exactly if the classes don't inherit, of course), but not the Ui I defined in any way.

    Can somebody clearify my misunderstanding(s)?

    BTW: I can post the Ui-Files (generates to the Designer), if needed.

    Thanks a lot in advance!

    Best regards Jan

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jankoh
      wrote on last edited by
      #2

      Hi there again,

      I found out, if I use
      @
      void qBandHelper::showMemberDialog( void )
      {
      QDialog *dlg = new QDialog;
      qBandMembers *memb = new qBandMembers(dlg);

      dlg->show();
      

      }
      @
      the correct window is created, but obviously when I want to destroy it by clicking OK/Cancel in the window (there is a buttonBox in there, which calls QWidget::close(), only the qBandMember objects are destroyed, but not the window itself.

      There must be an easier (or more likely) correct way to generate/destroy a subwindow...

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jjoe
        wrote on last edited by
        #3

        Have a look for "Qt::WA_DeleteOnClose":http://doc.qt.digia.com/qt/qt.html#WidgetAttribute-enum

        bq. Makes Qt delete this widget when the widget has accepted the close event (see QWidget::closeEvent()).

        Add the follwing line before you call show

        @dlg->setAttribute(Qt::WA_DeleteOnClose);@

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Amartel
          wrote on last edited by
          #4
          1. If you want to create a dialog you should inherit QDialog (Add new -> Qt -> Qt Designer Form Class -> QDialog)
          2. Adding your widget via designer is: add standard parent (QWidget for example) -> right click -> promote to... (the rest is obvious)
          3. You should create objects with parents ("Read manual for more info":http://qt-project.org/doc/qt-4.8/qobject.html#QObject)
          4. If you do not want to use designer, you still should use layouts (something like this):
            @QDialog *dlg = new QDialog(this);
            QHBoxLayout *layout = new QHBoxLayout(dlg);
            qBandMembers *memb = new qBandMembers(dlg);
            layout->addWidget(memb)

          dlg->show();@

          P.S.: Qt::WA_DeleteOnClose is also a very good choice; it is used, if you want to delete your dialog without deleting it's parent.

          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