Linux 无法使用 Qt 应用程序连接到 X 服务器:0.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/646930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot connect to X server :0.0 with a Qt application
提问by ant2009
Compiling on Fedora 10.
在 Fedora 10 上编译。
I have just started my first qt GUI application. I used all the default settings.
我刚刚开始我的第一个 qt GUI 应用程序。我使用了所有默认设置。
Its just a simple form. It builds OK without any errors. But when I try and run the application. I get the following message:
它只是一个简单的形式。它构建正常,没有任何错误。但是当我尝试运行应用程序时。我收到以下消息:
Starting /home/rob/projects/qt/test1/test1/test1...
No protocol specified
test1: cannot connect to X server :0.0
Thanks for any advice,
感谢您的任何建议,
采纳答案by Kent Fredric
The general causes for this are as follows:
造成这种情况的一般原因如下:
DISPLAY not set in the environment.
Solution:export DISPLAY=:0.0 ./myQtCmdHere
( This one doesn't appear to be the one at fault though, as its saying which X display its trying to connect to. Also, its not always 0.0, but most of the time it is )
Non-Authorised User trying to run the X Application
Solution( as X owning user, ie: yourself )xhost +local:root # where root is the local user you want to grant access to.
DISPLAY 未在环境中设置。
解决方案:export DISPLAY=:0.0 ./myQtCmdHere
(虽然这似乎不是那个有错的,因为它说哪个 X 显示它试图连接。此外,它并不总是 0.0,但大多数时候它是)
尝试运行 X 应用程序
解决方案的非授权用户(作为 X 拥有用户,即:你自己)xhost +local:root # where root is the local user you want to grant access to.
回答by dicroce
Also, if you'd like your X server to be able to receive connection over TCP, these days you must almost always explicitly enable this. To test whether you're server is allowing remote TCP connections try:
此外,如果您希望 X 服务器能够通过 TCP 接收连接,那么现在您几乎总是必须明确启用它。要测试您的服务器是否允许远程 TCP 连接,请尝试:
telnet 127.0.0.1 6000
远程登录 127.0.0.1 6000
If telnet is able to connect, then your X server is listening. If it can't, then neither will any remote X application and you need to enable remote TCP connections on your server.
如果 telnet 能够连接,那么您的 X 服务器正在侦听。如果不能,则任何远程 X 应用程序都不能,您需要在服务器上启用远程 TCP 连接。
回答by Tushar Gautam
Adding to above answers. I was in a similar situation while running tests for Code2Pdfat travis. I solved the problem using xvfb-run. Quoting from the manpage,
补充上面的答案。我在 travis 上运行Code2Pdf测试时遇到了类似的情况。我使用xvfb-run解决了这个问题。从联机帮助页中引用,
xvfb-run is a wrapper for the Xvfb(1x) command which simplifies the task of running commands (typically an X client, or a script containing a list of clients to be run) within a virtual X server environment.
xvfb-run 是 Xvfb(1x) 命令的包装器,它简化了在虚拟 X 服务器环境中运行命令(通常是 X 客户端,或包含要运行的客户端列表的脚本)的任务。
The script that I wrote was:
我写的脚本是:
check_install_xvfb() { # check and install xvfb
if hash xvfb-run 2>/dev/null; then
:
else
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install xvfb
fi
}
check_install_xvfb
export DISPLAY=localhost:1.0
xvfb-run -a bash .misc/tests.sh
# .misc/tests.sh is script that runs unit tests. You can replace it with something suitable to you.
Please bear with my bash code style. I am a noob bash programmer.
请忍受我的 bash 代码风格。我是一个菜鸟 bash 程序员。
Running the above script helped me. You can see the failing buildand passing build.
运行上面的脚本对我有帮助。您可以看到失败的 build和通过的 build。
Hope it helps
希望能帮助到你