当前位置:网站首页>[qt] meta object system
[qt] meta object system
2022-07-27 00:35:00 【Sy++】
The meta object system consists of three parts :
QObject Base class : The base class of all classes that use the meta object system
Q_OBJECT macro : Enable classes to use the properties of meta objects , Such as dynamic properties 、 Signals and slots, etc
MOC: Cloud object compiler , For each QObject Subclasses of provide the necessary code to implement the characteristics of the meta object system
besides , Meta objects also provide the following functions :
- QObject::metaObject() function
return QMetaObject—— Class associated meta objects , It contains some interface functions for accessing meta objects , for example QMetaObject::className() function , You can return the name string of the class .
- QMetaObject::newInstance() function
Create a new instance of the class
- QObject::inherits(const char* className) function
Judge whether an object instance is named className Class or QObject An instance of a subclass of , for example :
QTimer *timer=new QTimer;
timer->inherits("QTimer"); //true
timer->inherits("QObject"); //true
timer->inherits("QAbstractButton"); //false- QObject::tr() and QObject::trUtf8() function
Translate string , For multilingual interface design
- QObject::setProperty(const QString &name,value) and QObject::property(const QString &name) function
Used to pass the attribute name , Set and get attribute values dynamically , for example :
QPerson p;
p->setProperty("name"," Xiao Ming ");
p->property("name").toString();// The return is " Xiao Ming "- qobject_cast<T *>(className) Coercive transformation
Can be className class , Cast to its base class , for example :
QObject *obj=new QMyWidget;
QWidget *widget=qobject_cast<QMyWidget*>(obj);Usually with sender() Function coordination , To cast the obtained signaled class into its base class , Easy to operate .
边栏推荐
- Leetcode high frequency question: the choice of the inn, how many options to choose accommodation, to ensure that you can find a coffee shop with a minimum consumption of no more than p yuan in the ev
- 机器人学台大林教授课程笔记
- [LeetCode] 无重复最长字符串
- Friend友元函数以及单例模式
- 简单的素数程序 初学者 希望码龄高的大佬可以一下
- 【Codeforces Round #808 (Div 2.) A·B·C】
- Downloading and processing of sentinel-2
- Today's 20220719 toss deeplobcut
- [qt] attribute
- Based on the theoretical principle and simulation results of MATLAB spherical decoding, compare 2norm spherical decoding, infinite norm spherical decoding, ML detection
猜你喜欢

V-viewer use

CSDN article syntax rules

CDs simulation of minimum dominating set based on MATLAB

Openharmony quick start

Leetcode - hash table

Leetcode topic - binary tree chapter

继承,继承,继承

The crawler parses the object of the web page. Element name method

Complete review of parsing web pages

哨兵2号(Sentinel-2)的下载及处理
随机推荐
【Codeforces Round #807 (Div 2.) A·B·C】
放图仓库-Tsai
Configure deeplobcut2 with your head covered
Downloading and processing of sentinel-2
Mysql常用函数(汇总)
[4.2 approximations]
傅里叶分析(基础介绍)
Anaconda = > pycharm=> CUDA=> cudnn=> pytorch environment configuration
继承,继承,继承
5_线性回归(Linear Regression)
[qt] container class, iterator, foreach keyword
6_梯度下降法(Gradient Descent)
用New,delete和用malloc,free申请,释放堆区空间
Web middleware log analysis script 2.0 (shell script)
"Could not load host key" error when xshell connects to the server
Request attribute in crawler
Uni app learning (II)
V-viewer use
【4.2 约数】
Linux系统中安装Redis-7.0.4