Skip to content

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

@GinRyan

Description

@GinRyan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions