我正在使用 Code::Blocks 8.02 和 mingw 5.1.6编译器.编译 Qt 项目时出现此错误:
I'm using Code::Blocks 8.02 and the mingw 5.1.6 compiler. I'm getting this error when I compile my Qt project:
C:Documents and SettingsTheFuzzDesktopGUIApp_interface.cpp|33|未定义参考`地址簿的vtable'
C:Documents and SettingsThe FuzzDesktopGUIApp_interface.cpp|33|undefined reference to `vtable for AddressBook'
文件 AddressBook.h:
File AddressBook.h:
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include <QWidget>
class QLabel;
class QLineEdit;
class QTextEdit;
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
private:
QLineEdit *nameLine;
QTextEdit *addressText;
};
#endif
文件 AddressBook.cpp:
File AddressBook.cpp:
#include <QtGui>
#include "addressbook.h"
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent)
{
QLabel *nameLabel = new QLabel(tr("Name:"));
nameLine = new QLineEdit;
QLabel *addressLabel = new QLabel(tr("Address:"));
addressText = new QTextEdit;
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(nameLabel, 0, 0);
mainLayout->addWidget(nameLine, 0, 1);
mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
mainLayout->addWidget(addressText, 1, 1);
setLayout(mainLayout);
setWindowTitle(tr("Simple Address Book"));
}
警告:如果您已经有 .pro 文件,请不要这样做 - 您会丢失它!
为了自动保证生成所有的moc cpp文件,可以让qmake自动为你生成.pro文件,不用自己写.
In order to automatically ensure that all moc cpp files are generated, you can get qmake to automatically generate a .pro file for you instead of writing one yourself.
运行
qmake -project
在项目目录中,qmake 将扫描您目录中的所有 C++ 头文件和源文件,以生成 moc cpp 文件.
in the project directory, and qmake will scan your directory for all C++ headers and source files to generate moc cpp files for.
这篇关于对 vtable 的未定义引用.尝试编译 Qt 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!