Add external signal on QAction



  • Hello,

    is there some possibility to add new signal to the QAction? With QPushButton you can do it easily but QAction does not know any signals except the pre defined signals.



  • Tell us more about what are you trying to achieve.

    Anyway generic answers are: you can derive from QAction class and add the functionality you need, but first look at the "signals that are already there":http://doc.qt.digia.com/qt/qaction.html#signals - maybe what you need is already there.

    Also you can connect signal to signal - so triggered signal can trigger one of your signals.



  • By clicking on open icon on the toolbar I want to call another class, which is done in the slot.
    @
    QAction* openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
    openAct->setShortcuts(QKeySequence::Open);
    openAct->setStatusTip(tr(" an existing file"));
    connect(openAct, SIGNAL(setName(QString)), this, SLOT(callTheClass(QString)));
    @

    The problem is the signal: setName(QString) is not accepted by QAction



  • This doesn't make a lot of sense. The QAction indeed doesn't have a setName(QString) signal, but also it has no way to know what the name should be.

    However, I guess what you could do, is create a QAction-derived class that shows a file open dialog that allows you to select a file, and then emit a signal with the selected file name. However, I think this is the wrong place to put this functionality.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.