SeriousAlexej / TabToolbar

A small library for creating tabbed toolbars
Other
284 stars 108 forks source link

How to connect signal and slots for itemType = "action"? #16

Open GinRyan opened 10 months ago

GinRyan commented 10 months ago

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