初识Qt-无法解析的外部符号

跟着教程学习QT, 第一个对象树就出现bug,自己建立一个QPushButton的类,

复制代码
#ifndef MYPUSHBUTTON_H
#define MYPUSHBUTTON_H
#include <QPushButton>
class MyPushButton:public QPushButton
{    Q_OBJECT
public:   
 MyPushButton(QWidget *parent);   
 ~MyPushButton();
};
#endif // MYPUSHBUTTON_H
复制代码
#include "mypushbutton.h"
#include <QDebug>
MyPushButton::MyPushButton(QWidget *parent):QPushButton(parent)
{    qDebug()<<"HELLO WORLD";}
MyPushButton::~MyPushButton()
{    
qDebug()<<"BYE WORLD";
}

建立好类之后,在Widget.cpp中添加按钮:

MyPushButton *btn2=new MyPushButton(this);

btn2->setParent(this);

btn2->setText("MY Button");

btn2->move(200,100);

结果一直提示:

MyPushButton是一个无法解析的外部符号!

解决方案:

打开.pro文件,

复制代码
QT       += core gui后面添加QPushButton的父类,widgets,也就是

QT += core gui widgets,qmake一下,再运行,成功!

相关推荐
xcyxiner1 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner2 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner2 天前
DicomViewer (添加模型类)3
qt
xcyxiner3 天前
DicomViewer (目录调整) 2
qt
xcyxiner3 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR0065 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术5 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园5 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob5 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享5 天前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm