How to show another window from mainwindow in QT

How to show another window from mainwindow in QT

Asked on January 3, 2019 in Qt.
Add Comment


  • 1 Answer(s)

    Window from mainwindow in QT:

    • In  slot  QMainWindow  will open  a new Window,
    • The part of a widget  are in QMainWindow,
    • They join a signal  from the widget to a  channel from the QMainWindow  if the widget is  QPushButton  join  the signal click() to the QMainWindow custom channel.

    The given code is:

    MainWindow.h

    // ...
    include "newwindow.h"
    // ...
    public slots:
    void openNewWindow();
    // ...
    private:
    NewWindow *mMyNewWindow;
    // ...
    }
    

    MainWindow.cpp

    // ...
        MainWindow::MainWindow()
        {
            // ...
           connect(mMyButton, SIGNAL(click()), this, SLOT(openNewWindow()));
           // ...
        }
    // ...
    void MainWindow::openNewWindow()
    {
        mMyNewWindow = new NewWindow(); // Be sure to destroy your window somewhere
        mMyNewWindow->show();
        // ...
    }
    

       Now display a custom on new window.

    Answered on January 3, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.