Results 1 to 9 of 9

Thread: Undefined reference to signal

  1. #1
    Join Date
    Feb 2012
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Undefined reference to signal

    Hi all,
    I have a problem that could be very stupid, but I'm not able to solve it.
    I'm tring to be aware when an operator click with mouse on a qwtPlot, and have a class informed with a signal of the mouse position on the plot where he clicked.

    These are the pieces of code.
    Header:
    Qt Code:
    1. #include <QMouseEvent>
    2. #include <QDebug>
    3. #include <qwt_plot.h>
    4.  
    5. class QwtPlotMy : public QwtPlot
    6. {
    7. public:
    8. QwtPlotMy(int idPlotValue = 0);
    9.  
    10. signals:
    11. void clickSignal();
    12.  
    13. private:
    14. void mousePressEvent(QMouseEvent * event);
    15.  
    16. int idPlot;
    17. };
    To copy to clipboard, switch view to plain text mode 
    Cpp:
    Qt Code:
    1. #include "qwtplotmy.h"
    2.  
    3. QwtPlotMy::QwtPlotMy(int idPlotValue) :
    4. {
    5. idPlot = idPlotValue;
    6.  
    7. return;
    8. }
    9.  
    10. void QwtPlotMy::mousePressEvent(QMouseEvent * event)
    11. {
    12. emit (clickSignal());
    13. qDebug() << "Into qwtplot"<<idPlot;
    14. qDebug() << "x"<< event->x() << " - y"<< event->y() ;
    15. return;
    16. }
    To copy to clipboard, switch view to plain text mode 
    The problem is: compiling I get the message error:
    Qt Code:
    1. undefined reference to 'QwtPlotMy::clickSignal()'
    To copy to clipboard, switch view to plain text mode 

    If I comment the "emit (clickSignal())" line everything works well and I have the mouse position in the debug messages. Where I missed something?

    Thank you very much in advance,
    Carlo
    Last edited by chinalski; 26th July 2012 at 16:33.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to signal

    you defined your signal in QwtPlotMy , but emit it from QwtPlotAnteo.
    QwtPlotAnteo knows nothing about that signal.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2012
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Undefined reference to signal

    I'm sorry, High_flyer,
    I changed the names o function and I forgot to change one.
    No, this is not the problem, I send from QwtPlotMy, now I correct the names.

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

    Default Re: Undefined reference to signal

    You're missing the Q_OBJECT macro.
    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.


  5. #5
    Join Date
    Feb 2012
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Undefined reference to signal

    Quote Originally Posted by wysota View Post
    You're missing the Q_OBJECT macro.
    I thought it was the macro missing, but if I put the "Q_OBJECT" line I have a lot of errors:
    Qt Code:
    1. undefined reference to 'vtable for QwtPlotMy'
    To copy to clipboard, switch view to plain text mode 
    and I continue to have the usual error:
    Qt Code:
    1. undefined reference to 'QwtPlotMy::clickSignal'
    To copy to clipboard, switch view to plain text mode 
    The code that I posted is related to a bigger project, where I use signals and slot without problems, so I don't think that the "undefined reference to 'vtable for QwtPlotMy'" can be that the libraries are not found by the linker, but maybe I'm wrong.
    Last edited by chinalski; 26th July 2012 at 18:30.

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

    Default Re: Undefined reference to signal

    Quote Originally Posted by chinalski View Post
    I thought it was the macro missing, but if I put the "Q_OBJECT" line I have a lot of errors.
    Because you didn't 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.


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

    chinalski (26th July 2012)

  8. #7
    Join Date
    Feb 2012
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Undefined reference to signal

    Quote Originally Posted by wysota View Post
    Because you didn't run qmake after adding the macro to an existing file.
    Thank you very much wysota (and High_flyer)! I knew it was something simple! I'm so sorry to have asked such a stupid question.
    Goodbye

  9. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Undefined reference to signal

    Nevertheless your code won't work as you want to catch events of the plot canvas ( not the plot widget itsself ). Here you have to install en event filter instead of overloading mousePressEvent.

    Uwe

  10. #9
    Join Date
    Feb 2012
    Posts
    17
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Undefined reference to signal

    Quote Originally Posted by Uwe View Post
    Nevertheless your code won't work as you want to catch events of the plot canvas ( not the plot widget itsself ). Here you have to install en event filter instead of overloading mousePressEvent.
    Thank you Uwe, I'm studying the "bode" example to understand exactly what you said to me (I hope it is the right example).
    In any case, I'm working with mouse press event now, because I'm working on my PC, but the target will be a touch event, because the real hardware will be a touch screen interface.
    I think what you said will be the same, even on touch screen.
    Bye, c

Similar Threads

  1. Undefined reference to my signal
    By tomek in forum Newbie
    Replies: 9
    Last Post: 1st December 2011, 07:14
  2. undefined reference
    By deepakswaroop in forum Newbie
    Replies: 1
    Last Post: 2nd March 2011, 06:46
  3. Undefined reference
    By eekhoorn12 in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2011, 15:45
  4. undefined reference
    By jayreddy in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2009, 13:45
  5. Undefined Reference To...
    By ManuMies in forum Qt Programming
    Replies: 6
    Last Post: 10th February 2009, 12:14

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.