Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMenu action triggered and slot
QtWS25 Last Chance

QMenu action triggered and slot

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cfdevC Offline
    cfdevC Offline
    cfdev
    wrote on last edited by
    #1

    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 ??

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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.

      cfdevC 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        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.

        cfdevC Offline
        cfdevC Offline
        cfdev
        wrote on last edited by
        #3

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

        error: undefined reference to `vtable for MCTextEdit'
        
        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • cfdevC Offline
            cfdevC Offline
            cfdev
            wrote on last edited by
            #5

            Ok many thanks Chris!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved