Here is my code:
#include <QApplication> #include <QtWidgets> #include <QMenu> #include <QMenuBar> #include <main/MainMenu> int main(int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow w; w.show(); MainMenu m(a); w.setMenuBar(&m); return a.exec(); }
MainMenu is my class:
class MainMenu{ public: MainMenu(QApplication app,QWidget *parent = Q_NULLPTR):QMenuBar(parent){ QMenu *pm_file = new QMenu("&Меню"); pm_file->addAction("&Выйти", &app, SLOT(quit()),Qt::ALT + Qt::Key_F4); this->addMenu(pm_file); } };
But when I try to compile, I get the error C2248: QApplication::QApplication: невозможно обратиться к private член, объявленному в классе "QApplication"
in the MainMenu m(a);
. That is, as I understand it, I cannot access the QApplication constructor, although I don’t need it here ... What could be the error? In general, I want to establish a connection in my class with the quit()
slot, maybe there is another way for this?