Skip to content

Instantly share code, notes, and snippets.

@tracernz
Last active September 13, 2019 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracernz/5b24ee0bd1e3f065ff3712cdf7708f3a to your computer and use it in GitHub Desktop.
Save tracernz/5b24ee0bd1e3f065ff3712cdf7708f3a to your computer and use it in GitHub Desktop.
QAction::ApplicationSpecificRole demo
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QAction>
#include <QMenuBar>
#include <iostream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
auto action = new QAction("Test");
action->setMenuRole(QAction::ApplicationSpecificRole);
connect(action, &QAction::triggered, []{ std::cout << "lol" << std::endl; });
auto file = menuBar()->addMenu("File");
file->addAction(action);
}
MainWindow::~MainWindow()
{
delete ui;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment