当前位置:网站首页>qobject_cast用法
qobject_cast用法
2022-07-01 18:46:00 【初学小白Lu】
qobject_cast()动态转换QObject类的类型。
T qobject_cast ( QObject * object )
本方法返回object向下的转型T,如果转型不成功则返回0,如果传入的object本身就是0则返回0
示例:
QObject *obj = new QTimer; // QTimer inherits QObject
QTimer *timer = qobject_cast<QTimer *>(obj);
// timer == (QObject *)obj
QAbstractButton *button = qobject_cast<QAbstractButton *>(obj);
// button == nullptr
使用限制:
T类型必须继承自QObject
在声明时必须有Q_OBJECT宏。
用法–sender()函数
QPushButton *button_tmp=qobject_cast<QPushButton *>(sender());
当某一个Object emit一个signal的时候,它就是一个sender,系统会记录下当前是谁emit出这个signal的,所以你在对应的slot里就可以通过 sender()得到当前是谁invoke了你的slot,对应的是QObject->d->sender.
边栏推荐
- 研究了11种实时聊天软件,我发现都具备这些功能…
- Solution and summary of Nacos startup failure
- 自定义插入页面标签以及实现类似通讯录的首字母搜索
- win10下使用msys+vs2019编译ffmpeg源码
- 2022/5/23-2022/5/30
- 为什么一定要从DevOps走向BizDevOps?
- Mysql查询结果去除换行
- Why must we move from Devops to bizdevops?
- Interview questions for audio and video positions in Dachang -- today's headline
- JS 之 常用内置类的使用
猜你喜欢
随机推荐
2022/6/8-2022/6/12
118. 杨辉三角
[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function
Task: denial of service DOS
【AI服务器搭建】CUDA环境
Transaction isolation level gap lock deadlock
[SQL optimization] the difference between with as and temporary tables
torch. nn. functional. Interpolate function
[English grammar] Unit1 articles, nouns, pronouns and numerals
[untitled]
DDR4 test-2
H264编码profile & level控制
Simplified pinduoduo product data
Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
求各种极限的方法
Crunch简介、安装,使用Crunch制作密码字典
音频编解码基础知识
GetMessage底层机制分析
OpenCV视频质量诊断----视频遮挡诊断
Basic knowledge of audio coding and decoding