Qt 中出现 “The class containing “Ui::***“ could not be found in ***” 问题的解决过程

现象

Qt 的一个工程,之前是正常的,做了一点修改后,出现了错误,表现是:

在 UI 界面编辑窗口中,选中某个 按钮,右键选择 “Go to slot…” 后,出现错误,错误提示是 “The class containing “Ui::xxx1” could not be found in xxx2. Please verify the #include-directives” (xxx1 是类名,xxx2 是路径)。

解决方法

我觉得应该是我做了什么修改导致的,工程可以正常编译,可以正常运行,只是无法通过 UI 界面编辑窗口 添加槽函数了。最后,我发现是这个原因:
在这里插入图片描述

看图中的红框部份,可能是不同写法导致 Qt Creator 解析文件时出了错误
注意 这个方法不一定适用于所有情况,要具体分析

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
This error message usually occurs when the required Qt platform plugin "xcb" is not found or cannot be loaded. "xcb" is the X Window System backend used by Qt for rendering graphical user interfaces. To resolve this issue, you can try the following steps: 1. Install the necessary dependencies: Make sure that you have all the required dependencies installed for running Qt applications with the XCB platform plugin. On most Linux distributions, you can install these dependencies using the package manager. For example, on Ubuntu, you can run the following command: ``` sudo apt-get install libxcb-xinerama0 ``` 2. Verify the plugin installation: Check if the "xcb" platform plugin is available in the plugins/platforms directory of your Qt installation. The exact path may vary depending on your system and Qt version, but it is typically located in a directory like "Qt/5.X.Y/gcc_64/plugins/platforms". If the "xcb" plugin is missing, you may need to reinstall Qt or compile it with support for the XCB platform plugin. 3. Set the correct environment variable: Ensure that the environment variable `QT_QPA_PLATFORM_PLUGIN_PATH` is set correctly. This variable should point to the directory containing the Qt platform plugins. You can set it in your application's startup script or in your system's environment variables. For example, on Linux, you can run the following command to set the variable temporarily for testing: ``` export QT_QPA_PLATFORM_PLUGIN_PATH=/path/to/qt/plugins/platforms ``` 4. Check library paths: Make sure that the required Qt libraries and plugins are present in the system's library search path. You can verify this by running the `ldd` command on your application binary and checking if all the Qt dependencies are resolved correctly. By following these steps, you should be able to resolve the "Could not load the Qt platform plugin" error and successfully run your Qt application with the XCB platform plugin.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值