Results 1 to 3 of 3

Thread: Q_Object in class inherited by QwtPlot - Undefined Reference

  1. #1
    Join Date
    Jul 2013
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Q_Object in class inherited by QwtPlot - Undefined Reference

    Hi to all,

    I have some very strange problems.

    I would like to add the Q_OBJECT macro to a class called Plot, inherited by QwtPlot.

    I did everything in the right way and if I replace QwtPlot by QObject it works.

    If I inherit by QwtPlot I get an "Undefined reference" error by the linker, it complains about missing QMetaObject const QwtPlot::staticMetaObject ...

    The .pro file is:
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2017-03-08T16:00:42
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    10.  
    11. TARGET = Test
    12. TEMPLATE = app
    13.  
    14.  
    15. SOURCES += main.cpp\
    16. mainwindow.cpp \
    17. plot.cpp
    18.  
    19. HEADERS += mainwindow.h \
    20. plot.h
    21.  
    22. FORMS += mainwindow.ui
    23.  
    24. INCLUDEPATH += C:\Qwt-6.1.3\include
    25. LIBS += -LC:\Qwt-6.1.3\lib\ -lqwt
    To copy to clipboard, switch view to plain text mode 

    The plot.h is:
    Qt Code:
    1. #ifndef PLOT_H
    2. #define PLOT_H
    3.  
    4. #include <QObject>
    5. #include <qwt_plot.h>
    6.  
    7. class Plot: public QwtPlot
    8. {
    9. Q_OBJECT
    10. public:
    11. Plot(QWidget *parent);
    12. };
    13.  
    14. #endif // PLOT_H
    To copy to clipboard, switch view to plain text mode 

    Funny thing is that they do it in pretty much the same way in the examples of Qwt.

    Does anyone know how to solve this problem, please?
    Thanks a lot.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Q_Object in class inherited by QwtPlot - Undefined Reference

    LIBS += -LC:\Qwt-6.1.3\lib\ -lqwt
    Are you trying to link a debug mode app with a release mode Qwt or vice-versa? When you derive from QObject, qmake will link everything to the right Qt libraries depending on whether you are building in debug or release mode, but I am not sure what happens in the case of linking to Qwt. It may depend on whether you have built Qwt with the right options.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2013
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Q_Object in class inherited by QwtPlot - Undefined Reference

    After many hours I found out that I need to append
    Qt Code:
    1. DEFINES += QWT_DLL
    To copy to clipboard, switch view to plain text mode 
    in my project file.

    I don't know why I have to do this but it works.

    Thanks.

Similar Threads

  1. Replies: 6
    Last Post: 21st November 2015, 20:28
  2. Replies: 0
    Last Post: 7th July 2012, 12:32
  3. Replies: 0
    Last Post: 15th July 2011, 04:21
  4. Replies: 4
    Last Post: 28th May 2011, 22:57
  5. Replies: 6
    Last Post: 14th May 2009, 13:02

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.