初识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一下,再运行,成功!

相关推荐
故事还在继续吗几秒前
DPDK免锁队列
开发语言·dpdk
诙_几秒前
深入理解C++--STL
开发语言·c++
Mr数据杨3 分钟前
【Codex】搭建教学中心数据工作台统筹教案与课件资源
java·开发语言·django·codex·项目开发
枫叶丹47 分钟前
【HarmonyOS 6.0】Data Augmentation Kit 智慧化数据检索 C 接口解析:向量化、知识检索与知识问答
c语言·开发语言·华为·harmonyos
TANGLONG22220 分钟前
【C++】STL基础必备:深入解析vector容器的实现(含源码)
c语言·开发语言·数据结构·c++·笔记·算法·stl
50万马克的面包24 分钟前
C语言第3讲:分支和循环
c语言·开发语言·笔记·算法
ytttr87325 分钟前
惯性导航精解算程序(MATLAB实现)
开发语言·matlab
艺杯羹26 分钟前
从零搭建CSDN博客爬虫:Python爬虫+多格式导出完整教程
开发语言·爬虫·python·开源·gui·csdn
码农小韩30 分钟前
QT学习记录(三)——C++学习基础(三)
开发语言·c++·qt·学习·算法·嵌入式软件