Getting the Qt VNC Server to work

trenki picture trenki · Apr 21, 2011 · Viewed 10.8k times · Source

I compiled and installed Qt for Embedded Linux and made sure to use -qt-gfx-vnc in the ./configure line.

I start my application with the following code.

int argc = 1;
char *argv[] = { "appname", "-display", "VNC:0" };
QApplication app(argc, argv, QApplication::GuiServer);

Without the "-display", "VNC:0" options the application works using the display of the embedded device but with these options a QVNCServer is created on port 5900 and nothing goes to the display any more. Trying to connect using Ubuntu's Remove Desktop Viewer does not work. It gives just a black screen and no error message.

For my application I need a VNC Server that is active while the GUI is rendered to the embedded display at the same time. Ideally I would also want to be able to enable/disable the VNC Server from within my application. I also need to be able to do some user authentication.

Is it possible to have have a VNC Server and the standard qws stuff running at the same time using Qt or do I have to find another solution?

Answer

chetto picture chetto · Oct 29, 2011

The "QVNCServer created on port 5900" indicates your Qt libraries were compiled to include the Qt VNC server. The QVNCServer is not a full VNC server, but is a Qt display driver where the output is made available as a VNC Server on the network interface. The "VNC server" is not a separate process, and is simpler than a full VNC server in that it can only handle 1 VNC client at a time and it only supports VNC clients that connect with a depth of 32bpp. There is a bug in the Qt version I am using (4.2.2) that causes the QVNCServer to appear to hang if a VNC client attempts to connect with depth=8 (which is a default for many portable device VNC clients). This may be your problem connecting to the QVNC server. Make sure your VNC client is configured as 32bit/24bit/full-color/high-color. I patched my QtGui library source code so it would disconnect immediately if the VNC client doesn't have a depth=32.

Below are the parameters to launch the Qt application from the command line, but the same strings work when launched by another program as you show in your example.

To launch the application only on the VNC display:

  appname -qws -display "VNC::"
  appname -qws -display "VNC::size=640x480:depth=32:0"

To launch the application to display the same output simultaneously on both the local Linux framebuffer (/dev/fb0) (in my case the local display driver is "sm501") and a remote VNC client use the following:

  appname -qws -display "Multi: sm501: VNC::"

(I had to use 2 colons with VNC though it was not obvious from the documentation.)

The easiest way to display different content on the local display and the VNC client is to launch separate Linux processes, each specifying a different display. You can support multiple VNC clients by launching applications with different VNC port numbers:

  appname1 -qws                    --renders to the local display
  appname2 -qws -display VNC::0   --renders to VNC port 5900
  appname3 -qws -display VNC::1   --renders to VNC port 5901
  appname4 -qws -display VNC::2   --renders to VNC port 5902