如何使用 QtCreator 远程调试图形应用程序? [英] How to remotely debug graphic application with QtCreator?
问题描述
我开发了一个跨平台的 Qt 应用程序.现在我需要/想要在带有 GUI 表单加载的远程主机上运行它.
我知道有两种方法可以做到这一点:
I develop a cross-platform Qt application. And now I need/want to run it on a remote host with GUI form loading.
I know 2 ways to do that:
- 在远程显示器(可能是虚拟的)上打开应用程序,控制台通过
ssh
连接到 QtCreator - 使用远程 X 会话运行,就像使用
ssh -X
或-Y
一样.
- open application on a remote display (may be virtual) with console attached to QtCreator via
ssh
- run with remote X session, like it done with
ssh -X
or-Y
.
当我在远程设备上通过 QtCreator 运行应用程序时,它说
When I run an application through QtCreator on the remote device it says
QXcbConnection: Could not connect to display
当我使用 ssh -Y
连接到远程主机并运行我的应用程序时,它说
When I connect to remote host with ssh -Y
and run my app, it says
QXcbConnection: Could not connect to display localhost:10.0
Aborted
在我的本地主机和通过 VNC 的远程主机上,应用程序运行良好.
On my local host and on remote host via VNC the application works fine.
ssh -Y user@host xclock
也可以正常工作 - 在我的本地显示器上打开它的表单.
ssh -Y user@host xclock
also works fine - opens it's form on my local display.
主机系统是 Ubuntu 16.04 LTS x64,目标系统是 Ubuntu 16.04 LTS x86 32 位.Qt 版本 5.9.1
Host system is Ubuntu 16.04 LTS x64, target system Ubuntu 16.04 LTS x86 32bit. Qt version 5.9.1
请帮助我让它工作.在最坏的情况下,我同意在 QtCreator 和 gdb
中看到调试控制台,但 GUI 仍然可以放置在远程显示器上.
Please help me to make it work. In worst case I agree to see debug console in and gdb
attached to QtCreator, but the GUI could still be placed on a remote display.
更新:这是关于 form.qt.io.
推荐答案
经过一些研究和 QtCreator 社区的帮助,我发现
方法很简单:
After some research and help from QtCreator community I found
The way is simple:
- 打开与远程主机的 ssh 会话并启用 X 转发
ssh -X user@host
.并了解DISPLAY
变量.例如echo $DISPLAY
.它应该看起来像localhost:10.0
. - 在 QtCreator -> Projects -> YourConfiguration -> Run -> RunEnvironment 中将环境变量
DISPLAY
设置为 (1) 中的已知值. - 在本地机器上使用 GUI 运行并享受远程调试.
- Open ssh session to remote host with X forwarding enabled
ssh -X user@host
. And get know theDISPLAY
variable. For example withecho $DISPLAY
. It should look likelocalhost:10.0
. - Set environment variable
DISPLAY
in QtCreator -> Projects -> YourConfiguration -> Run -> RunEnvironment to known value from (1). - Run and enjoy remote debug with GUI on local machine.
注意:关闭 ssh 会话将使转发的显示无法访问且无效.
Note: closing ssh session will make forwarded display inaccessible and invalid.
这篇关于如何使用 QtCreator 远程调试图形应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!