Search code examples
c++qtqt5qmenuqaction

In QT5, how to open new window on click event on sub-menu item?


I am new to QT programming & UI designing. I want to open a new window when the user clicks on submenu or menu item. I can successfully open a new window when the user clicks on a button.

Below the image of my main window. I want to open new window when the user click on 'password' menu item

When the user clicks on test button, New window opens successfully.

Any help would be highly appreciated.


Solution

  • Create a slot:

    public slots:
        void slot();
    

    Connect the signal triggered() with this slot

    connect({your QAction}, SIGNAL(triggered()), this, SLOT(slot()));
    

    Open the window from the slot.

    void {your QMainWindow}::slot(){
       //open yout window here
    }