对 vtable 的未定义引用.尝试编译 Qt 项目

Undefined reference to vtable. Trying to compile a Qt project(对 vtable 的未定义引用.尝试编译 Qt 项目)
本文介绍了对 vtable 的未定义引用.尝试编译 Qt 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)