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.
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
What is the license for this code?
Can i using it for my company project?
@Amin @everyone Is anyone having working version of client?
Hi Amin,
Can i get any code reference for VNCserver?
Unfortunately I don’t have any. Google might help.
For a project I am working on I am looking for a VNC client application for Qt. I found your implementation and this looks like a good basis for our implementation.
But I could not find any information on the license your code in distributed under. Can I use your code in our application, or is it covered by a specific license?
You can use it as you wish.
Dear Amin,
I have some issues with the client. When I try to connect the client to a server, it only works sometimes (and completely), the other times I just have a black screen but I can move the mouse cursor and click. The connexion seems working, but the screen is not shared. I have the impression with the logs that the parameters are not well received by the client because I have some negatives values that are not present when the connexion totally works.
Is it the encryption/decryption parts that are not working or is it something else ?
What do you think about it ?
I really need your help to solve my issue, because your work is the only one that give good results on the web.
Best regards and thanks for your time.
Unfortunately I won’t be able to support you with much details because it’s been quite some time since I worked on this, but since you have the code and you’ve already tried to make it work, then perhaps you can also fix the bugs you are facing as well. To give you a reference point where you can start, I recommend reading the official protocol for VNC which is The Remote Framebuffer Protocol. Here is a link to the article:
https://tools.ietf.org/html/rfc6143
Sorry if I can’t help more.
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……..
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);
Just a question. Any way to port this c++ code to python3 ?
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.
have you ported this to python? if yes can you help me with the code.
Sorry for the late response afal,
Unfortunately I don’t have a port of this for Python.
I’s from a long time ago 🙂 I won’t get any free time to port it.
Since I needed a Python port myself for PyQt5, I have ported your C++ to Python3. You can find it here
https://github.com/zocker-160/pyQVNCWidget
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.
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 ?
Can you confirm if you can make it work on desktop platforms? Windows, macOS, Linux doesn’t really matter.
I launch your client on Android application from Qt Creator from mac os.
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).
Hi, i’ve the same problem. Have you solved ?
I can’t see the frames render.
Unfortunately this sounds like an update to the protocol or something like that.
You might be able to fix it yourself if you dig deep into the protocol specifications.
Here is a link for you:
https://tools.ietf.org/html/rfc6143
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 ?
It might have something to do with your server. This widget only supports standard connection types, security types and so on. Try reading this to familiarize yourself with the protocol. I hope it helps.
https://tools.ietf.org/html/rfc6143