问题描述
运行ROS初始教程时,有个小乌龟的事例,rosrun turtlesim turtlesim_node
,结果报错,如下所示:
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
已放弃 (核心已转储)
但这我记得以前在其他机器上安装后也没出现上述问题,于是又只好百度+google。
解决过程
这个是Qt的问题,错误信息简短,是说找不到Qt的一个插件,但感觉这个应该都已经安装好了,要不就在安装过程中集成好了,怎么会找不到?但我也确实不知道这个错误涉及的文件在哪。
1. locate libqxcb.so
ubuntu 16.04 Qt error: it could not find or load the Qt platform plugin "xcb"有一些相关的部分,但错误信息又不是很一致,值的庆幸的是拿到了locate libqxcb.so
这个命令,看来xcb文件是与这个libqxcb.so
文件错误有关,而这个命令输出结果如下:
/home/user/anaconda3/pkgs/qt-5.9.7-h5867ecd_1/plugins/platforms/libqxcb.so
/home/user/anaconda3/plugins/platforms/libqxcb.so
/home/user/webots/lib/webots/qt/plugins/platforms/libqxcb.so
/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so
前3条路径是用户也就是我创建的,最后一条是系统路径。这时起码排除了文件不存在的问题,应该是库路径出错了导致库找不到了(对应路径下确实存在文件),但我并不知道接下来该如何做,也没意识到可能导致的版本冲突问题。
2. export QT_DEBUG_PLUGINS=1
qt.qpa.plugin: Could not find the Qt platform plugin “xcb” in "/opt/Qt-5.12.4/plugins"这篇文章中提到可以使用export QT_DEBUG_PLUGINS=1
来打印错误详细信息,这个可以在shell
里面直接敲,不用加入.bashrc
文件。确实,有更详细的调试信息才能更准确地解决问题。此时命令rosrun turtlesim turtlesim_node
输出结果如下:
QFactoryLoader::QFactoryLoader() checking directory path "/opt/ros/kinetic/lib/turtlesim/platforms" ...
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
已放弃 (核心已转储)
但上述路径/opt/ros/kinetic/lib/turtlesim/platforms
不存在,再者上述博客将export QT_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins/
添加进