How to pass a QAction to a Qt slot from a QMenu

554 views Asked by At

Iam new in Qt and I have problem how to pass QAction as parameter like this code:

connect(fileToolBarAct, SIGNAL(toggled(bool)), this, SLOT(ToggleBar(fileToolBarAct));

And this my slots function:

void MainWindow::ToggleBar(QAction& what)
{
    what.isCheckable();
}
2

There are 2 answers

0
Iuliu On BEST ANSWER

QObject::connect doesn't work like this. You can not pass objects to SIGNAL and SLOT macros. SIGNAL and SLOT macros should take function signatures. In addition the signature of a signal must match the signature of the receiving slot as described in the Qt documentation.

I see that you lack in understanding the signals and slots mechanism and I recommend you read the Qt Signals and Slots documentation for more info. Reading the Qt Signals and Slots documentation will clear everything for you.

0
mike510a On
onnect(fileToolBarAct, SIGNAL(toggled(bool)), this, SLOT(ToggleBar(bool));


void MainWindow::ToggleBar(bool checked)
{
    QAction* action = qobject_cast<QOAction*>(sender());
    if (action) 
         action->setChecked(checked);
}