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

相关推荐
敲代码的瓦龙1 分钟前
操作系统相关的一些问题总结
linux·c语言·开发语言
牛奔4 分钟前
php 8.2 配置安装php-zbarcode扩展
android·开发语言·php
Fcy64820 分钟前
C++ 模版(进阶)(含array解析)
开发语言·c++·stl·array·模版
OKkankan26 分钟前
多态概念及使用
开发语言·数据结构·c++·算法
hudawei99626 分钟前
kotlin协程编译成Android字节码后是什么样的
android·开发语言·kotlin
小周码代码36 分钟前
js 数字金额转为大写 js 金额转大写
开发语言·前端·javascript·js工具
行走在电子领域的工匠38 分钟前
台达ST:自定义串行通讯传送与接收指令COMRS程序范例五
开发语言·台达plc·st语言编程·串口自定义协议
BillKu1 小时前
html2pdf.js使用与配置详解
开发语言·javascript·ecmascript
n***s9091 小时前
ThinkPHP和PHP的区别
开发语言·php
code bean1 小时前
【C++】全局函数和全局变量
开发语言·c++·c#