English 中文(简体)
不详的提及。 汇编Qt项目
原标题:Undefined reference to vtable. Trying to compile a Qt project
  • 时间:2009-10-11 23:25:57
  •  标签:

http://en.wikipedia.org/wiki/Code:Blocks"rel=“noreferer” 法典:Blocks8.02 和 mingw 5.1.6 编辑。 在我汇编我的Qt项目时,我发现这一错误:

C:Documents and SettingsThe FuzzDesktopGUIApp_interface.cpp|33|undefined reference to `vtable for AddressBook

档案地址Book.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

档案地址Book.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"));
}
最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 警告: 如果你已经掌握了文件,你就会失去文件!

为了自动确保产生所有磁卷文档,你可以自动为你编制一个文件,而不是撰写一份文件。

页: 1

qmake -project

项目目录和qmake将扫描所有C++头目和源文档的目录,以生成 mo积文档。

问题回答

在使用Qt造物时:

  1. Build → Run qmake
  2. Build → Rebuild All

问题几乎肯定是,你在编造的 mo-备案卷中,没有联系。 (本应为您生成——在编辑之前,你正在使用moc。

为了更彻底地回答,Q_OBJECT宏观信号 Qt s moc tool to establish an extra implementation file that contained the code necessary to support QObject s meta-information system. 如果你有任何信号或位置,那也会为这些人做一些事情。

另一种解决办法可以是删除<代码>Q_OBJECT宏观。 也许你不想这样做,但会帮助解决眼前的问题,而且你提出的法典是绝对必要的。

此外,我还要指出,你的行文如下:

#include "addressbook.h"

可能的话是:

#include "AddressBook.h"

根据你是如何提出所涉档案名称的。

假设你正在利用面包车制作你的成文书,则确保地址Book.h在您的“pro file s HEADERS”中具体注明,例如。

HEADERS = AddressBook.h

就CMake项目而言,将CMAKE-AUTOMOC安排到O,这就确定了我的问题。

#Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

我在使用纯虚拟功能时就这样做。 例如,

virtual void process();

引出这一错误,但

virtual void process() = 0;

这使它消失。

For anyone who s Googling this problem, check that all virtual functions are defined. (via " = 0" or a full definition in the source file) I m using Netbeans with the MinGW compiler.

我正在使用电离线处理同样的问题,并通过向电离辐射分子添加这些线来解决这一问题。 txt

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

我也存在同样的问题,但一旦我把我的施工者定义为主人,而不是将错误消失。 另外,在档案系统和Makfile的“编织者_moc_header_make_all”中,也缺少相应的 mo。 当时,我跑了一辆面包车,最后是用uc子建造的。 我去检查马克茨,现在就到那里。

删除了建筑夹、重新启用的盖特造物,并发挥了作用

I come to the same problem, rebuild the project never update the Makefile, I remove the Makefile and rebuild , the the problem is gone. ps: run make from command line may give you detail information than the IDE, and helpful to get the real problem.

原因之一是,你宣布某类人员为虚拟职务,而你没有界定其身体。

在我的案件中,Rebuild All是不够的,我不得不删除建筑目录,使Rebuild All——然后工作!

Simply Run qmake for their project. 可以通过在您的项目名称上进行右lick,并在<代码>上点击来做到这一点。 页: 1

明确该项目,然后重建!

Go to .pro file and make sure .h file has include before it. HEADERS += include/file.h include/file2.h

我也想利用受保护的虚拟功能。 两件事奏效。

  1. Changing void process(); to void process() = 0;
  2. Making process() public instead of private

如果你意外地增加一台脱轨器原型,你将获得同样的错误信息。 添加空洞的电离层定义或删除原型。

CMake

在使用CMake时,如果我的电灯和.子的档案没有与 mo的 same子一样,那么光有意思的是, default子和bu子没有生成:

the most errors from using Q_OBJECT but not generate moc file
the moc file define
classname::metaObject
staticMetaObject
qt_metacall

Here is a example:
when source or header using Q_OBJECT

/opt/qt/bin/moc ./window.h -o /moc_window.cpp

Makefile add moc_window.o in OBJS
Ex: OBJS=main.o window.o moc_window.o

try this source
https://www.mediafire.com/file/anjeah1jmm07mfe/qt_group_box.tar.gz

见http://fatalfeel.blogspot.com/2008/11/qt5-c-building.html。

我正在利用Qt创建者来汇编和管理我的节目,我不经常使用Qt 即时指挥。 删除“可贵的东西”的一句,在.pro文档中添加以下内容。

TEMPLATE = 服

QT + = 核心





相关问题
热门标签