QT:获取对象的类名 [英] QT : get the class name of an object
问题描述
我正在编写一个测试应用程序来模拟另一个应用程序的按键操作.对于每次按键,我都必须检查是否显示了正确的窗口/表单.所以我要做的是获取正在显示的窗口的指针并获取它的窗口标题.但是,并非所有窗口/窗体都显示窗口标题.所以我认为最好获取类的名称.我怎样才能得到班级的名字?
I'm writing a test app that simulates key presses of another application. For every key press I have to check if the right window/form is shown. So what I do is get the pointer of the window being shown and get it's window title. However, not all the windows/forms shown window titles. So I'm thinking it would be better to get the name of the class instead. How can I get the name of the class?
QWidget *pWin = QApplication::activeWindow();
当我尝试时:
pWin->className();
要获取类的名称,我得到:
to get the name of the class, I'm getting:
"错误:类 QWidget 没有名为 'className' 的成员"
"error: class QWidget has no member named 'className' "
有人可以告诉我正确的方法吗?
Can somebody show me the right way?
推荐答案
尝试使用 元对象.
pWin->metaObject()->className();
这篇关于QT:获取对象的类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!