QXcbConnection: Could not connect to display, when trying to debug Linux app with Qt Creator

后端 未结 2 1701
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 18:49

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

相关标签:
2条回答
  • 2021-01-25 19:03

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

    0 讨论(0)
  • 2021-01-25 19:09

    When you deploy your application and run it from within the X11 system on device itself, you're finding it works because here it has access to the DISPLAY environment variable which (briefly put) tells it where to display itself. This environment variable has been set further up the process tree in your X session.

    When you launch a program via the debugger, Qt Creator is connecting to the remote device (via your settings in Tools > Options > Devices), and running the program via ssh. In this context your program no longer knows where to display itself, as obviously it can't display in ssh. It faults on the line you indicated because this is where the XCB subsystem is trying to determine which X-Server to connect to for this purpose.

    So to answer your question: you need to manually provide the DISPLAY environment variable when remote debugging.

    An easy way to test this is to go to Projects Mode, find the kit you are using to build for the remote device, and select the Run settings. Under this, you should find an Run Environment section. Here you can add a new variable called DISPLAY and set its value to the identifier of the display you are running on (I'm guessing you'll want :0.0, indicating the first available screen on localhost, although you should read about the DISPLAY variable e.g. here or here).

    A longer-term, potentially better solution would be to set the same variable in the settings of your Kit (Tools > Options > Build & Run > Kits > Environment). This will then apply for future programs you create using this.

    0 讨论(0)
提交回复
热议问题