Results 1 to 3 of 3

Thread: error when adding signal slot to a QGLWidget based class

  1. #1
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default error when adding signal slot to a QGLWidget based class

    I have a QGLWidget based class that worked fine untill I add a signal slot
    connection, so I can use a context menu, like the menu example in Qt assitant (only I'm
    using it in a QGLWidget instead of the main window).
    My class:

    Qt Code:
    1. #include <QGLWidget>
    2. #include <QMenu>
    3. #include <QObject>
    4.  
    5. class GLGraph : public QGLWidget
    6. {
    7. // Q_OBJECT // this line causes the error
    8.  
    9. public:
    10. GLGraph();
    11. ~GLGraph();
    12. .....
    13. protected:
    14. virtual void contextMenuEvent(QContextMenuEvent *event);
    15.  
    16. ...
    17. private:
    18. .....
    19. void createActions();
    20. QAction *newInterpolAct;
    21. ....
    22. private slots:
    23. void newInterpol();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void GLGraph::contextMenuEvent(QContextMenuEvent *event)
    2. {
    3. if (!flag_Interpolation)
    4. return;
    5.  
    6. QMenu menu(this);
    7. menu.addAction(newInterpolAct);
    8. menu.exec(event->globalPos());
    9. }
    10.  
    11. void GLGraph::createActions()
    12. {
    13. newInterpolAct = new QAction(tr("&New"), this);
    14. newInterpolAct->setShortcuts(QKeySequence::New);
    15. // newInterpolAct->setStatusTip(tr("Create a new Interpolation"));
    16. connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpolAct()));
    17. }
    18.  
    19. void GLGraph::newInterpol()
    20. {
    21. QMessageBox::about(this,"","nova interpol");
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 
    My errors:

    Qt Code:
    1. D:/qt4examples/Matematica/glgraph.cpp:9: undefined reference to `vtable for GLGraph'
    2. D:/qt4examples/Matematica/glgraph.cpp:9: undefined reference to `vtable for GLGraph'
    3. D:/qt4examples/Matematica/glgraph.cpp:9: undefined reference to `vtable for GLGraph'
    4. D:/qt4examples/Matematica/glgraph.cpp:9: undefined reference to `vtable for GLGraph'
    5. D:/qt4examples/Matematica/glgraph.cpp:41: undefined reference to `vtable for GLGraph'
    6. D:/qt4examples/Matematica/glgraph.cpp:41: undefined reference to `vtable for GLGraph'
    7. :-1: error: collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    The error occurs when I use Q_OBJECT in the class declaration. The lines 9 and 41 are
    the first bracket lines of the construtor and destructor. If I remove the Q_OBJECT the
    program works, the context menus apears but doesnt connect and I get a message in the
    Qtcreator compile output window:

    Qt Code:
    1. Object::connect: No such slot QGLWidget::newInterpolAct() in glgraph.cpp:439
    To copy to clipboard, switch view to plain text mode 
    this line is:

    Qt Code:
    1. connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpolAct()));
    To copy to clipboard, switch view to plain text mode 

    Any ideas on this error ???????????

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: error when adding signal slot to a QGLWidget based class

    Always run qmake after adding the macro to an existing file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    john_god (11th April 2009)

  4. #3
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Talking Re: error when adding signal slot to a QGLWidget based class

    THANK YOU very much

    Also had other stupid mistake, I had:

    Qt Code:
    1. connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpolAct()));
    To copy to clipboard, switch view to plain text mode 
    instead of:
    Qt Code:
    1. connect(newInterpolAct, SIGNAL(triggered()), this, SLOT(newInterpol()));
    To copy to clipboard, switch view to plain text mode 

    Works fine now !!!!!

Similar Threads

  1. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  2. Replies: 12
    Last Post: 18th September 2008, 15:04
  3. Signal in base class Slot in Subclass
    By csvivek in forum Newbie
    Replies: 7
    Last Post: 30th March 2008, 16:59
  4. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  5. Replies: 2
    Last Post: 4th May 2006, 19:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.