触发时无法对函数进行 link QAction (Qt 5)
Unable to link QAction to a function when triggered (Qt 5)
我正在尝试将上下文菜单添加到系统托盘(可通过单击系统托盘图标激活)我已成功添加菜单和带有文本的操作 "Exit",但我不知道如何操作到 link 动作 "triggered" 功能到另一个功能/更改触发功能或其他任何有效的功能。我只是想在单击操作时激活某些特定行为。当我单击此操作按钮时,它不会执行任何操作。我尝试 link 使用此构造函数将其传递给成员函数:QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = ...)
这是我的代码中最重要的部分:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
mSystemTrayIcon = new QSystemTrayIcon(this);
mSystemTrayIcon->setIcon(QIcon(":/iris_logo.png"));
mSystemTrayIcon->setVisible(true);
systemTrayMenu = new QMenu("Context menu");
systemTrayMenu->setToolTipsVisible(true);
// I get the error: no matching member function for call to 'addAction'
systemTrayMenu->addAction("Open", this, on_actionQuit_triggered()));
// I dont get an error, however this only creates a menu button, not its corresponding function that must be called.
systemTrayMenu->addAction("Exit");
mSystemTrayIcon->setContextMenu(systemTrayMenu);
}
addAction
returns指向QAction
对象的指针,得到这个指针并使用connect
在triggered
信号和[=15之间建立连接=]插槽:
QAction* openAction = systemTrayMenu->addAction("Open");
connect (openAction, SIGNAL(triggered()) , this, SLOT(on_actionQuit_triggered()));
我正在尝试将上下文菜单添加到系统托盘(可通过单击系统托盘图标激活)我已成功添加菜单和带有文本的操作 "Exit",但我不知道如何操作到 link 动作 "triggered" 功能到另一个功能/更改触发功能或其他任何有效的功能。我只是想在单击操作时激活某些特定行为。当我单击此操作按钮时,它不会执行任何操作。我尝试 link 使用此构造函数将其传递给成员函数:QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = ...)
这是我的代码中最重要的部分:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
mSystemTrayIcon = new QSystemTrayIcon(this);
mSystemTrayIcon->setIcon(QIcon(":/iris_logo.png"));
mSystemTrayIcon->setVisible(true);
systemTrayMenu = new QMenu("Context menu");
systemTrayMenu->setToolTipsVisible(true);
// I get the error: no matching member function for call to 'addAction'
systemTrayMenu->addAction("Open", this, on_actionQuit_triggered()));
// I dont get an error, however this only creates a menu button, not its corresponding function that must be called.
systemTrayMenu->addAction("Exit");
mSystemTrayIcon->setContextMenu(systemTrayMenu);
}
addAction
returns指向QAction
对象的指针,得到这个指针并使用connect
在triggered
信号和[=15之间建立连接=]插槽:
QAction* openAction = systemTrayMenu->addAction("Open");
connect (openAction, SIGNAL(triggered()) , this, SLOT(on_actionQuit_triggered()));