对vtable的未定义引用。试图编译一个Qt项目 [英] Undefined reference to vtable. Trying to compile a Qt project

查看:168
本文介绍了对vtable的未定义引用。试图编译一个Qt项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Code :: Blocks 8.02和mingw 5.1.6编译器。我在编译我的Qt项目时收到此错误:


C:\Documents和Settings \The
Fuzz \Desktop\GUI\App_interface.cpp | 33 | undefined
对`vtable for AddressBook'的引用


文件

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:

  #include< QtGui> 
#includeaddressbook.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));
}


解决方案



运行


,可以使用qmake自动生成一个.pro文件

  qmake -project 

项目目录,qmake将扫描您的目录中的所有C ++头和源文件以生成moc cpp文件。


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 Settings\The Fuzz\Desktop\GUI\App_interface.cpp|33|undefined reference to `vtable for AddressBook'

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

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"));
}

解决方案

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.

Run

qmake -project

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项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆