TabToolbar
TabToolbar copied to clipboard
How to connect signal and slots for itemType = "action"?
How to connect signal and slots for itemType = "action"?
There's an action like:
{
"itemType": "action",
"type": "instantPopup",
"name": "actionExit"
}
But when I find actionExit that it occurs and nullptr.
Example:
QToolButton *actionExit = (QToolButton *)ttb["actionExit"];
if (actionExit != nullptr) {
QObject::connect(actionExit, &QToolButton::triggered, this,
&CMainWindow::actionExit);
} else {
cout << "Error: actionExit is null" << endl;
}
output:
"Error: actionExit is null".
I replaced QToolButton* to QAction*, but it doesn't work.
Or it goes:
QToolButton *actionExit = (QToolButton *)ttb["actionExit"];
QObject::connect(actionExit, &QToolButton::triggered, this,
&CMainWindow::actionExit);
or
QAction *actionOpen = (QAction *)ttb["actionOpen"];
QObject::connect(actionOpen, &QAction::triggered, [tabToolbar, this]() {
QMessageBox::information(this, "OK", "OK");
});
They all output:
QObject::connect(QAction, Unknown): invalid nullptr parameter
please help me