QVncServer Class

The QVncServer is a QTcpServer which supports the RFB® protocol. More...

Header: #include <QVncServer>
CMake: find_package(Qt6 REQUIRED COMPONENTS VncServer)
target_link_libraries(mytarget PRIVATE Qt6::VncServer)
qmake: QT += vncserver

Public Types

enum ServerState { Uninitialized, Listening, Connected, InitializationFailed }


Public Functions

QVncServer(const QSize &screenSize, QImage::Format screenFormat, int port = -1)
virtual ~QVncServer() override
const QByteArray &password() const
int port() const
void provideImage(const QImage &image, bool flippedVertically = false)
QImage::Format screenFormat() const
QRect screenGeometry() const
QImage screenImage(bool *isFlipped = nullptr) const
QVncServer::ServerState serverState() const
void setCursor(QCursor *cursor)
void setPassword(const QByteArray &newPassword)


Detailed Description

The QVncServer can be used to create a TCP server which accepts connections from VNC®-compatible clients.

Member Type Documentation

enum QVncServer::ServerState

QVncServer::Uninitialized0The server has not been initialized yet.
QVncServer::Listening1The server is listening for connections on the requested port.
QVncServer::Connected2At least one client is connected to the server.
QVncServer::InitializationFailed3The server failed to initialize.

Property Documentation

password : QByteArray

This property holds the password for the VNC®-compatible server. By default, the property is the empty string. If left empty, no authentication will be enabled for the server. If set, it will enable DEC authentication.

Note: DEC authentication is considered weak protection, and the connection itself is not encrypted. This protects mainly against accidental intrusion, but not against targeted attacks.

Access functions:

const QByteArray &password() const
void setPassword(const QByteArray &newPassword)

Notifier signal:

void passwordChanged()

[read-only] port : const int

This read-only property holds the port the server is currently listening to (if the server is in the Listening state.)

This will typically be the port requested in the constructor, but if a negative port is requested, then this property will reflect the actual port in use.

Access functions:

int port() const

Notifier signal:

void portChanged()

[read-only] serverState : const ServerState

This property indicates the current state of the server.

Access functions:

QVncServer::ServerState serverState() const

Notifier signal:

void serverStateChanged()

Member Function Documentation

[explicit] QVncServer::QVncServer(const QSize &screenSize, QImage::Format screenFormat, int port = -1)

Constructs a QVncSserver with the given screenSize and screenFormat. This will open a TCP server listening for RFB® connections on port.

If a negative port number is requested, then the server will cycle through the default ports from 5900 to 5999 until it successful in listening. This can be useful if there are other remote desktop services running on the same machine, which may already be occupying the default port.

[override virtual noexcept] QVncServer::~QVncServer()

Destroys the QVncServer. This will disconnect all clients.

void QVncServer::provideImage(const QImage &image, bool flippedVertically = false)

Sets the current image provided to clients. For images where the vertical origin is at the bottom, pass true for flippedVertically, otherwise false.

Note: If the size or format of the image is different from the current size or format, the server's parameters will be updated. This requires support in the connected clients for updating image parameters while they are connected.

See also screenImage().

QImage::Format QVncServer::screenFormat() const

Returns the format passed to the constructor.

QRect QVncServer::screenGeometry() const

Returns the a rectangle spanning from (0, 0) with the dimensions passed to the constructor.

QImage QVncServer::screenImage(bool *isFlipped = nullptr) const

Returns the current image shared by the server to clients. If isFlipped is not null, its contents will be set to true if the current image's origin is at the bottom, and false if it is at the top.

Note: This function is thread-safe.

See also provideImage().

void QVncServer::setCursor(QCursor *cursor)

Provides a cursor for clients supporting this.

Available under certain Qt licenses.
Find out more.