我正在继承 QwtPlot 。我有以下错误:

moc_myplot.obj:-1: 错误: LNK2001: 未解析的外部符号 "public: static struct QMetaObject const QwtPlot::staticMetaObject"(?staticMetaObject@QwtPlot@@2UQMetaObject@@B)
我尝试了以下操作:运行 qmake、重建、清理、删除调试文件夹、重新编译 qwt 库。那没有帮助。这是最小的代码:
我的情节.h:

#ifndef MYPLOT_H
#define MYPLOT_H
#include <QObject>
#include <qwt_plot.h>

class MyPlot : public QwtPlot
{
    Q_OBJECT
public:
    MyPlot();
};

#endif // MYPLOT_H

myplot.cpp:
#include "myplot.h"

MyPlot::MyPlot()
{

}

这是 .pro 文件:
#-------------------------------------------------
#
# Project created by QtCreator 2015-06-22T19:33:24
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = MyPlot
TEMPLATE = app


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

HEADERS  += mainwindow.h \
    myplot.h

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../qwt-6.1.2/lib/ -lqwt
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../qwt-6.1.2/lib/ -lqwtd
else:unix: LIBS += -L$$PWD/../../../../../qwt-6.1.2/lib/ -lqwt

INCLUDEPATH += $$PWD/../../../../../qwt-6.1.2/include
DEPENDPATH += $$PWD/../../../../../qwt-6.1.2/include

我正在使用基于 Qt 5.4.2(MSVC 2013,32 位)的 Qt Creator 3.4.1。套件: 桌面 Qt 5.4.2 MSVC2013 64 位 。编译器: Microsof Visual C++ 编译器 12.0(amd64) 。如果我在 Q_OBJECT 中注释 myplot.h 宏,则一切正常。我可以在没有子类化的情况下使用 qwt_plot,这样 this->setCentralWidget(new QwtPlot()); 中的 mainwindow.cpp 行就可以了。

最佳答案

似乎这是一个旧的 issue,至少在 4.6 版中存在。

解决方法基本上是从“调用 QWT 的最低库”中定义 QWT_DLL 的预处理器。

关于c++ - LNK2001 : Unresolved external symbol when using qwt plot in Qt creator,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30985698/

10-11 22:44
查看更多