解决MobaXterm通过SSH启动远程Qt图形应用失败

背景

通过MobaXterm X11-forwarding 功能可以将远程图形应用投射到本地进行展示(因为MobaXterm本身内建X Server,可以直接执行远程端的X窗口程序,无需任何配置),如图1所示:
解决MobaXterm通过SSH启动远程Qt图形应用失败_第1张图片
图1 MobaXterm支持remote display forwaded through ssh

现象

运行图形化程序,报错如下:

QFactoryLoader::QFactoryLoader() checking directory path "/home/hzwangjb/nertc/sdk/demo/linux/qt_demo/dem                                            o/ci/Linux-NERtc-Demo/x86_64/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/hzwangjb/nertc/sdk/demo/linux/qt_demo/demo/ci/Linux-NE                                            Rtc-Demo/x86_64/plugins/platforms/libqxcb.so"
Found metadata in lib /home/hzwangjb/nertc/sdk/demo/linux/qt_demo/demo/ci/Linux-NERtc-Demo/x86_64/plugins                                            /platforms/libqxcb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "xcb"
        ]
    },
    "archreq": 0,
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 330752
}


Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/home/hzwangjb/nertc/sdk/demo/linux/qt_demo/dem                                            o/ci/Linux-NERtc-Demo/x86_64/platforms" ...
loaded library "/home/hzwangjb/nertc/sdk/demo/linux/qt_demo/demo/ci/Linux-NERtc-Demo/x86_64/plugins/platf                                            orms/libqxcb.so"
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the app                                            lication may fix this problem.

可以通知设置环境变量QT_DEBUG_PLUGINS=1打开调试开关,能看到更详细的信息

关键错误信息如下:

qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the app                                            lication may fix this problem.

排查下来Qt应用打包了libqxcb.so, 也找到了,网上google一圈也未能解决问题,重心放在了xcb问题上,直接原因是qt.qpa.xcb: could not connect to display, 没有设置DISPLAY环境变量。

解决办法

根因是笔者是通过控制台ssh指令进行登录的,导致MobaXterm没有正确配置DISPLAY,正确操作应该使用Session新建一个SSH终端,如下:

解决MobaXterm通过SSH启动远程Qt图形应用失败_第2张图片

你可能感兴趣的:(音视频,qt,ssh,linux)