nocturne nocturne - 1 year ago 110
C++ Question

Qt - connect menuBar and QWidget

So I have menu bar like this:

this->layout = new QGridLayout;
QMenuBar* menuBar = new QMenuBar();
QMenu *fileMenu = new QMenu("File");

And I am wonderig how to connect thie action
with some slot my
, I tryed something like this:


But it is not working, can you tell me what I am doing wrong? And yes I have read manual about QMenuBar bud there are no examples of connecting. I have read about some connecting in Qt Designer but I am not using it.

Answer Source

You need to connect the QAction pointer returned from QMenuBar::addAction to the slot...

auto *exit_action = fileMenu->addAction("Exit");
connect(exit_action, &QAction::triggered,
        [this](bool checked)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download