QMenu action triggered and slot



  • Hi everyone,

    I have created an derived class of QTextedit

    class MCTextEdit : public QTextEdit
    {
    ...
    private slots:
    	void replace_Word(QAction* act);
    

    And I created anQMenu and connect it to the slot, like this:

    for(int i=0; i<proposalList.count(); i++) {
    	menuSpell->addAction( new QAction(proposalList.at(i), this) );
    }
    connect(menuSpell, SIGNAL(triggered(QAction* )),
            this, SLOT(replace_Word(QAction* )), Qt::UniqueConnection);
    

    Compilation ok, but when I run the signal/slot conncetion doesn't work:

    Object::connect: No such slot QTextEdit::replace_Word(QAction* ) in ...
    

    why this message doesn't say me: No such slot MCTextEdit ::replace_Word ??


  • Moderators

    You are missing Q_OBJECT macro in your derived class so the base class (most derived QObject with that macro) is looked up for the slot, which it obviously doesn't have.
    Each class declaring its own signals or slots needs that macro.



  • @Chris-Kawa I suspected this macro! But when I declate it
    Ihave an error:

    error: undefined reference to `vtable for MCTextEdit'
    

  • Moderators

    You need to run your class through moc so it may generate the meta object code for your class. If you're using QtCreator then just go to Build -> run qmake, and that should do it.



  • Ok many thanks Chris!


Log in to reply
 

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