qt5.5.1 如何判断某个对象是否属于qt类中实例
2015-11-28 13:56
513 查看
根据qt5帮助文档,
bool QObject::inherits(const char * className) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
返回真,如果对象是指定的继承类或QObject类的子类的一个实例,就返真.否则返回甲.
Example:
QTimer *timer = new QTimer; // QTimer inherits QObject
timer->inherits("QTimer"); // returns true
timer->inherits("QObject"); // returns true
timer->inherits("QAbstractButton"); // returns false
// QVBoxLayout inherits QObject and QLayoutItem
QVBoxLayout *layout = new QVBoxLayout;
layout->inherits("QObject"); // returns true
layout->inherits("QLayoutItem"); // returns true (even though QLayoutItem is not a QObject)
如果您需要确定对象是否为特定类的实例, 建议用 qobject_cast<Type *>(object) 代替.
See also metaObject() and qobject_cast().
bool QObject::inherits(const char * className) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
返回真,如果对象是指定的继承类或QObject类的子类的一个实例,就返真.否则返回甲.
Example:
QTimer *timer = new QTimer; // QTimer inherits QObject
timer->inherits("QTimer"); // returns true
timer->inherits("QObject"); // returns true
timer->inherits("QAbstractButton"); // returns false
// QVBoxLayout inherits QObject and QLayoutItem
QVBoxLayout *layout = new QVBoxLayout;
layout->inherits("QObject"); // returns true
layout->inherits("QLayoutItem"); // returns true (even though QLayoutItem is not a QObject)
如果您需要确定对象是否为特定类的实例, 建议用 qobject_cast<Type *>(object) 代替.
See also metaObject() and qobject_cast().
相关文章推荐
- qt5程序头文件包含风格推荐
- Qt的时钟Example
- QT实现电子表digitalclock
- QT学习 之 事件与事件过滤器
- QT子窗口及停靠实现
- QT笔记(1)--QT编程环境搭建
- ubuntu Qt版本无效: qmake不存在或者不可执行
- Qt:正则表达式语法:
- QT:QBitArray
- Qt中moc问题(qt moc 处理 cpp)
- QVariant类的使用注意事项
- Qt中通过控件在Label标签中显示一张静态图片
- Qt使用教程之指定运行设置(二)
- qt+vs第二篇(designer的使用)
- qt+vs[基础控件介绍一]
- arm上打开摄像头
- Qt 将excel表添加到另一个表后面
- Qt:postEvent 与 customEvent() 函数 进行异步通信; 以及参数的传递 // 防止界面卡死;;
- 加快QT工程编译速度
- qt绘图相关的基础知识