触发时无法将 QAction 链接到函数 (Qt 5)
Unable to link QAction to a function when triggered (Qt 5)
我正在尝试将上下文菜单添加到系统托盘(可通过单击系统托盘图标激活(我已经成功添加了菜单和一个带有文本"退出"的操作,但是我不知道如何将操作"触发"功能链接到另一个功能/更改触发功能或其他任何可以工作的东西。我只是想在单击操作时激活某些特定行为。此操作按钮在我单击它时不执行任何操作。我尝试使用此构造函数将其链接到成员函数: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
返回指向QAction
对象的指针,获取此指针并使用connect
在信号triggered
和on_actionQuit_triggered
插槽之间建立连接:
QAction* openAction = systemTrayMenu->addAction("Open");
connect (openAction, SIGNAL(triggered()) , this, SLOT(on_actionQuit_triggered()));
相关文章:
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 如何在qt中从另一个类调用函数
- 触发时无法将 QAction 链接到函数 (Qt 5)
- QT 如何将 Qlist 传递给类构造函数
- 在 QT 中运行延迟的函数
- 如何将函数指针传递给方法,以便它可以在Qt的connect()中使用?
- 每次qt窗口获得焦点时调用函数
- Qt基类函数定义
- 在Qt应用程序中包含Python.h会导致对Qt函数的未定义引用
- 在Qt中使用C++Lambda函数作为插槽是否有助于保持库的二进制兼容性?
- QT - 连接 Qml 按钮 单击到 Cpp 构造函数
- C++,QT. QShortcut的函数调用不存在
- 如何结束图形GUI和执行控制台函数(QT)
- 如何使用拖放功能和点击信号函数QT创建标签
- 找不到 CPP 中来自外部源的函数 (Qt)
- 在构造函数 QT 创建器(继承类)中传递默认参数
- 从另一个函数的"if loop"中调用/移动一个函数 - Qt,C++
- 带有 QWidget 的分段错误构造函数.Qt/C++
- 析构函数 Qt QDialog 中的分段错误
- 构造函数 Qt C++ 中的枚举