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. Close button must close 2 windows
Forum Updated to NodeBB v4.3 + New Features

Close button must close 2 windows

Scheduled Pinned Locked Moved General and Desktop
9 Posts 6 Posters 10.8k 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.
  • B Offline
    B Offline
    browser90
    wrote on last edited by
    #1

    Dear,

    I've got 4 windows, 1 has the close button etc.., the other 3 windows have the close button disabled with "z.setWindowFlags ( Qt::CustomizeWindowHint | Qt::WindowTitleHint);" , now is it possible if the user clicks the close button of that one window that the other also closes? I don't find something usefull on google, can someone help please?

    Kind regards,

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Just connect the clicked signal of the button to the close signal of every window.
      @
      connect(closeButton, SIGNAL(clicked()), window1, SLOT(close()));
      connect(closeButton, SIGNAL(clicked()), window2, SLOT(close()));
      connect(closeButton, SIGNAL(clicked()), window3, SLOT(close()));
      connect(closeButton, SIGNAL(clicked()), window4, SLOT(close()));
      @

      1 Reply Last reply
      0
      • B Offline
        B Offline
        browser90
        wrote on last edited by
        #3

        Oké i've something like this:

        @

        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);
        connect(closeButton, SIGNAL(clicked()), MainWindow, SLOT(close()));
        connect(closeButton, SIGNAL(clicked()), Form, SLOT(close()));
        }
        @

        but it doesn't compile?

        Kind regards, thanks for your help already.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          You need to provide at least the compile error message(s) in addition.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zither
            wrote on last edited by
            #5

            I think you need to make point via ui if you use Designer to layout form.

            @connect(ui->closeButton, SIGNAL(clicked()), ui->MainWindow, SLOT(close()));
            connect(ui->closeButton, SIGNAL(clicked()), ui->Form, SLOT(close()));@

            It's my guess. You should provide error messages to know exact bug.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              browser90
              wrote on last edited by
              #6

              Sorry forgot to give the error message, i've done it with the ui pointer and these errors shows up:

              http://imageshack.us/photo/my-images/228/errk.png/

              @
              In constructor MainWindow:: MainWindow(qwidget*):
              class ui::mainwindow has no member named closebutton
              invalid use of class ui::mainwindow
              class ui:: mainwindow has no member named closebutton
              class ui::mainwindow has no member named form
              @

              thanks for the help

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

                I would guess, by "closebutten" browser90 means the button in the window's title bar, not a "regular" UI button. In this case, you should reimplement "QWidget::closeEvent() ":http://doc.qt.nokia.com/4.7/qwidget.html#closeEvent in your main widget class.

                Something like this should do the trick:

                @
                // to your .h file in the protected section:
                void closeEvent ( QCloseEvent * event );

                // add this to the implementation:
                void MainWindow::closeEvent ( QCloseEvent * event )
                {
                Form->close();
                OtherWindow->close();
                QMainWindow::closeEvent(event);
                }
                @

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

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  browser90
                  wrote on last edited by
                  #8

                  Thanks :-)

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    [quote author="browser90" date="1321300907"]Oké i've something like this:

                    @

                    MainWindow::MainWindow(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::MainWindow)
                    {
                    ui->setupUi(this);
                    connect(closeButton, SIGNAL(clicked()), MainWindow, SLOT(close()));
                    connect(closeButton, SIGNAL(clicked()), Form, SLOT(close()));
                    }
                    @

                    but it doesn't compile?

                    Kind regards, thanks for your help already.[/quote]

                    Seems to me you are confusing classes with objects (instances of classes). You can not connect to a class, you connect to an object.

                    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