我有一個由CMake驅動的庫和示例應用程序。所以,還有一類,就是我在圖書館使用:Qt應用中未定義的參考錯誤
sourceeditor.h
#ifndef SOURCEEDITOR_H
#define SOURCEEDITOR_H
#include <QWidget>
#include "novile_export.h"
namespace Novile
{
class SourceEditorPrivate;
class NOVILE_EXPORT SourceEditor : public QWidget
{
Q_OBJECT
public:
explicit SourceEditor(QWidget *parent = 0);
~SourceEditor();
private:
SourceEditorPrivate * const d;
};
} // namespace Novile
#endif // SOURCEEDITOR_H
sourceeditor.cpp
#include <QtCore>
#include <QVBoxLayout>
#include <QWebView>
#include "novile_debug.h"
#include "sourceeditor.h"
namespace Novile
{
class SourceEditorPrivate
{
public:
SourceEditorPrivate(SourceEditor *p = 0) :
parent(p),
aceView(new QWebView(p)),
layout(new QVBoxLayout(p))
{
parent->setLayout(layout);
layout->addWidget(aceView);
}
~SourceEditorPrivate()
{
}
void loadAceView()
{
aceView->load(QUrl("qrc:/ace.html"));
}
private:
SourceEditor *parent;
QWebView *aceView;
QVBoxLayout *layout;
};
SourceEditor::SourceEditor(QWidget *parent) :
QWidget(parent),
d(new SourceEditorPrivate(this))
{
mDebug() << "Source Editor has been started";
d->loadAceView();
}
SourceEditor::~SourceEditor()
{
}
} // namespace Novile
和示例:
主.cpp
#include <QApplication>
#include "../src/sourceeditor.cpp"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Novile::SourceEditor editor;
editor.setGeometry(100, 50, 600, 300);
editor.show();
return app.exec();
}
然後我收到很多ld
錯誤:
CMakeFiles/example.dir/main.cpp.o: In function `Novile::SourceEditor::SourceEditor(QWidget*)':
../src/sourceeditor.cpp:39: undefined reference to `vtable for Novile::SourceEditor'
../src/sourceeditor.cpp:39: undefined reference to `vtable for Novile::SourceEditor'
CMakeFiles/example.dir/main.cpp.o: In function `Novile::SourceEditor::~SourceEditor()':
../src/sourceeditor.cpp:46: undefined reference to `vtable for Novile::SourceEditor'
../src/sourceeditor.cpp:46: undefined reference to `vtable for Novile::SourceEditor'
collect2: error: ld returned 1 exit status
此文件(main.cpp中)表示的示例應用程序,這應該測試文庫的核心功能。
什麼是'd' ...? –
請告訴我們'sourceeditor.h'。 – Angew
你可能錯過了'Q_OBJECT'宏,但是由於你沒有顯示'SourceEditor'類的定義,很難說。 – Mat