QXcbConnection:尝试使用 Qt Creator 调试 Linux 应用程序时,无法连接到显示器

QXcbConnection:尝试使用 Qt Creator 调试 Linux 应用程序时,无法连接到显示器

问题描述:

我正在尝试将一组使用 Qt Creator 构建的 Windows 应用程序移植到 Linux.我已经在使用 VirtualBox 的 64 位 Ubuntu 16.04 虚拟机中安装了基于 Qt 5.7.0 的 Qt Creator 4.0.2.主机 PC 是 64 位 Windows 7 Professional.

I am trying to port a set of Windows applications that were built with Qt Creator to Linux. I have installed Qt Creator 4.0.2 based on Qt 5.7.0 in a 64-bit Ubuntu 16.04 virtual machine using VirtualBox. The host PC is 64-bit Windows 7 Professional.

我已经成功构建了一个应用程序项目,现在我正在尝试调试它.如果我尝试使用 F5 开始调试,Qt 会坚持尝试编译尚未编译的项目之一,因此我使用启动和调试外部应用程序...".

I have successfully built one of the application projects and I am now trying to debug it. If I try to start debugging with F5, Qt insists on trying to compile one of the projects that does not yet compile so I am using "Start and Debug External Application...".

应用程序立即在 main() 中崩溃:

The application immediately crashes in main() at the line:

QApplication app(argc, argv);

出现错误:QXcbConnection:无法连接到显示器.

with the error: QXcbConnection: Could not connect to display.

如果我从终端窗口运行可执行文件,则会显示 UI 并且应用程序正常运行.

If I run the executable from a terminal window, the UI is displayed and the application functions normally.

我需要做什么才能使用 Qt 调试 UI 应用程序.

What do I need to do to be able to debug a UI application with Qt.

原来我所要做的就是选中启动调试器"对话框窗口中的在终端中运行:"复选框.

Turns out that all I had to do was check the "Run in terminal:" check box in the "Start Debugger" dialog window.