28

Compiling on Fedora 10.

I have just started my first qt GUI application. I used all the default settings.

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,

NG_
  • 6,895
  • 7
  • 45
  • 67
ant2009
  • 27,094
  • 154
  • 411
  • 609

3 Answers3

47

The general causes for this are as follows:

  1. 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 )

  2. 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. 
    
Kent Fredric
  • 56,416
  • 14
  • 107
  • 150
  • 1
    Just a quick follow-up. What does this do: export DISPLAY=:0.0 and why did my application fail because of it? Thanks, – ant2009 Mar 14 '09 at 23:54
  • your display interface runs a server-client model. DISPLAY tells applications where thier screen is, usually IP:DISPLAY.SCREEN format, but without IP it uses localhost. But given the right conditions, you can 'throw' and app at any network accessible display. – Kent Fredric Mar 14 '09 at 23:59
5

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:

telnet 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.

dicroce
  • 45,396
  • 28
  • 101
  • 140
2

Adding to above answers. I was in a similar situation while running tests for Code2Pdf at travis. I solved the problem using xvfb-run. Quoting from the manpage,

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.

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.

Running the above script helped me. You can see the failing build and passing build.

Hope it helps

Tushar Gautam
  • 458
  • 6
  • 19