PDA

View Full Version : Q_Object in class inherited by QwtPlot - Undefined Reference



anjohn
10th March 2017, 09:57
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:

#-------------------------------------------------
#
# Project created by QtCreator 2017-03-08T16:00:42
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Test
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
plot.cpp

HEADERS += mainwindow.h \
plot.h

FORMS += mainwindow.ui

INCLUDEPATH += C:\Qwt-6.1.3\include
LIBS += -LC:\Qwt-6.1.3\lib\ -lqwt

The plot.h is:

#ifndef PLOT_H
#define PLOT_H

#include <QObject>
#include <qwt_plot.h>

class Plot: public QwtPlot
{
Q_OBJECT
public:
Plot(QWidget *parent);
};

#endif // PLOT_H

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.

d_stranz
11th March 2017, 02:35
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.

anjohn
13th March 2017, 07:59
After many hours I found out that I need to append

DEFINES += QWT_DLL
in my project file.

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

Thanks. :)