未定义对`vtable for MainWindow'的引用 [英] undefined reference to `vtable for MainWindow'

查看:163
本文介绍了未定义对`vtable for MainWindow'的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循 Qt指南来使用 QPushButton .

我确实按照指南的建议进行操作,但是出现编译错误:

I did exactly as the guide suggests, but I'm getting a compilation error:

./src/mainwindow.o: In function `MainWindow::MainWindow(QWidget*)':
mainwindow.cpp:(.text+0x1d): undefined reference to `vtable for MainWindow'
./src/mainwindow.o:mainwindow.cpp:(.text+0x25): more undefined references to `vtable for MainWindow' follow
collect2: error: ld returned 1 exit status
make: *** [HelloWorldProj] Error 1

我尝试添加析构函数:

~MainWindow(){};

但问题仍然存在.

我没有声明任何虚函数,除了 QMainWindow (我从其继承的类)中的一个函数:

I have no virtual functions declared, except one function inside QMainWindow (the class I'm inheriting from):

virtual QMenu *createPopupMenu();

这应该在我的课堂上定义吗?

Should this be defined in my class?

推荐答案

尝试在项目上运行qmake,然后进行重建.

Try running qmake on the project and then do a rebuild.

您的示例已损坏(如果可能,我会尽快对其进行更新)

Your example is broken (I will update it shortly if possible)

创建一个空文件并将其命名为PushButtonExample.pro并添加以下内容:

Create an empty file and name it PushButtonExample.pro and add the following:

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = PushButtonExample
TEMPLATE = app

SOURCES += main.cpp \
    mainwindow.cpp

HEADERS  += mainwindow.h

然后在该文件上运行 qmake ,然后在 make 上运行.

Then run qmake on that file, then make.

我还建议您下载Qt Creator并将其用作构建Qt项目时的IDE.大多数Qt安装程序还会安装Qt Creator IDE,并且有一些不错的示例和向导来创建新项目.

I also recommend that you download Qt Creator and use that as your IDE when building Qt project. Most Qt installs also install the Qt Creator IDE and it has some nice examples and wizards to create new projects.

确保所有4个文件都在同一文件夹中

Make sure all 4 files are in the same folder

main.cpp
mainwindow.cpp
mainwindow.h
PushButtonExample.pro

在命令行中,导航到该文件夹​​并运行qmake

In command line, navigate into that folder and run qmake

qmake PushButtonExample.pro

这应该在同一文件夹中创建以下文件

This should create the following file in the same folder

Makefile

然后运行 make

这应该构建示例,并最终运行该应用程序:

This should build the example, and finally run the application:

./PushButtonExample

(我也在更新Wiki页面)

(I am also updating the wiki page)

这篇关于未定义对`vtable for MainWindow'的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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