Full Featured VNC Client Widget for Qt

In this post I am going to share a Qt widget that allows full control (view and control) of VNC servers over TCP/IP. Using it is as simple as dropping a QWidget on your user interface and then promoting it to QVNCClientWidget. I needed this recently but was not able to find a Qt widget or any other Qt/C++ code for that matter, that supports VNC Authentication and can be used in a  real cross-platform way. So I had to gather and write this widget piece by piece and make sure it build on all platforms supported by Qt.

Below is an example screenshot of my QVNCClientWidget running on a Windows host to control a Mac OS X that has a VNC Server setup and running in it.

qt-vnc-widget-client-c

Just make sure you provide the server’s IP address and password to the connectToVncServer function. Then call startFrameBufferUpdate function to start viewing and controlling the server.

vncView->connectToVncServer("127.0.0.1", "MyPassword");
vncView->startFrameBufferUpdate();

Performance is not bad but it can be better if more compression supported protocols are developed into it.

Remember to call the following function when you need to disconnect from the server.

vncView->disconnectFromVncServer();

You can use the following Bitbucket repository the get the full source code to the widget and example project all in one place and ask your questions here if you had any.

https://bitbucket.org/amahta/qvncclient

13 Replies to “Full Featured VNC Client Widget for Qt”

  1. I try your program but face to somes issues.
    It is not possible to connect even if it is write connection successful !
    Check method connectToVncServer
    condition \x01 or \x02 are not available in my case small code tell me
    “Connection successful with security type \r\x85\x05\x81”

    please can you help ?

  2. Hi Amin,
    I’ve one problem, i can’t see the frames.
    This is the log, it’s connected from smartphone android, but in the viewer i see nothing.

    D libQVNCClient.so: ../QVNCClient/qvncclientwidget.cpp:20 (bool QVNCClientWidget::connectToVncServer(QString, QString, int)): Security Handshake
    D libQVNCClient.so: ../QVNCClient/qvncclientwidget.cpp:23 (bool QVNCClientWidget::connectToVncServer(QString, QString, int)): Server Answer : “FB 003.008\n”
    D libQVNCClient.so: ../QVNCClient/qvncclientwidget.cpp:39 (bool QVNCClientWidget::connectToVncServer(QString, QString, int)): Connection successful: response “”
    D libQVNCClient.so: ../QVNCClient/qvncclientwidget.cpp:132 (bool QVNCClientWidget::connectToVncServer(QString, QString, int)): Screen QImage(QSize(300, 200),format=4,depth=32,devicePixelRatio=1,bytesPerLine=1200,byteCount=240000)
    D libQVNCClient.so: ../QVNCClient/qvncclientwidget.cpp:202 (void QVNCClientWidget::sendFrameBufferUpdateRequest()): Response sendFrameBufferUpdate “”

    on ubuntu linux i had installe x11vnc
    Do you help me ?

        1. So does it work on macOS? I’m specifically asking about macOS since I’m not 100%sure that it works on Android, as it is (out-of-the-box).

  3. Without password it won’t work as you don’t send/receive the init messages then. Mouse button ids should be bit encoded. Mouse button release shoudln’t send the button as active. Use event->buttons() instead of event->button().
    A lot of socket->reads aren’t checked, so if any of them fail (not enough data available yet) the whole communication is broken.

    Just in case someone wants to work with your example, those are the points that need to be addressed.

    1. Well essentially this is just an implementation of VNC protocol with some additional features but the main part in interpreting and communication with VNC. So the answer is, yes of course it can be ported to Python, but not exactly as it is. It needs to be adapted to Python as well.

  4. Hello Amin.

    It is possible to use this code to connect to a webSocket? I have to connect to a vnc server but is emitting trough a websocket……..

    1. Hi William,
      As long as the server is on an accessible server (IP address and port number) you can connect to it.
      Here’s the connect function signature:
      bool connectToVncServer(QString ip, QString password, int port = 5900);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.