QT:获取对象的类名

发布于 2024-10-04 09:29:02 字数 393 浏览 1 评论 0原文

我正在编写一个测试应用程序来模拟另一个应用程序的按键操作。对于每次按键,我都必须检查是否显示正确的窗口/表单。所以我要做的就是获取正在显示的窗口的指针并获取它的窗口标题。但是,并非所有窗口/窗体都显示窗口标题。所以我想最好还是获取班级的名称。我怎样才能得到班级的名字?

QWidget *pWin = QApplication::activeWindow();

当我尝试:

pWin->className(); 

获取班级名称时,我得到:

“错误:类 QWidget 没有名为 'className' 的成员”

有人可以告诉我正确的方法吗?

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();

when I try:

pWin->className(); 

to get the name of the class, I'm getting:

"error: class QWidget has no member named 'className' "

Can somebody show me the right way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜心小果奶 2024-10-11 09:29:02

尝试使用元对象

pWin->metaObject()->className();  

Try using the metaobject.

pWin->metaObject()->className();  
月亮邮递员 2024-10-11 09:29:02

您还可以检查 typeinfo 标头。在对象上使用 typeid 运算符,您将获得一个描述对象类型的 type_info 实例。
查看:http://www.cplusplus.com/reference/std/typeinfo/type_info /

You could also check the typeinfo header. Using the typeid operator on you object you get a type_info instance which describes the type of your object.
Check out: http://www.cplusplus.com/reference/std/typeinfo/type_info/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文