C

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 }

Properties

Public Functions

QVncServer(const QSize &screenSize, QImage::Format screenFormat, int port = -1)
QVncServer(const QSize &screenSize, QImage::Format screenFormat, QHostAddress listeningAddress, 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
QByteArray serverName() const
QVncServer::ServerState serverState() const
void setCursor(QCursor *cursor)
void setPassword(const QByteArray &newPassword)
void setServerName(const QByteArray &newServerName)

Signals

void keyEventReceived(QEvent::Type eventType, Qt::Key key, Qt::KeyboardModifiers keyboardModifiers, const QChar &text)
void mouseEventReceived(QEvent::Type eventType, const QPointF &mousePosition, Qt::MouseButton mouseButton, Qt::MouseButtons mouseState, Qt::KeyboardModifiers keyboardState)
void passwordChanged()
void portChanged()
void serverNameChanged()
void serverStateChanged()
void wheelEventReceived(const QPointF &mousePosition, const QPoint &angleDelta, Qt::KeyboardModifiers keyboardState)

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

ConstantValueDescription
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()

[since 6.8] serverName : QByteArray

This property holds the name of the server. This name will be sent to connecting clients as part of the ServerInit message.

This property was introduced in Qt 6.8.

Access functions:

QByteArray serverName() const
void setServerName(const QByteArray &newServerName)

Notifier signal:

void serverNameChanged()

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

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

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

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.

[signal] void QVncServer::keyEventReceived(QEvent::Type eventType, Qt::Key key, Qt::KeyboardModifiers keyboardModifiers, const QChar &text)

Emitted when a key event is received.

eventTypeType of the event.
keyThe code of the key that was pressed or released.
keyboardModifiersKeyboard modifiers for the event.
textA character generated for the event (if any).

[signal] void QVncServer::mouseEventReceived(QEvent::Type eventType, const QPointF &mousePosition, Qt::MouseButton mouseButton, Qt::MouseButtons mouseState, Qt::KeyboardModifiers keyboardState)

Emitted when a mouse event is received.

eventTypeType of the event.
mousePositionMouse position for the event.
mouseButtonThe mouse button that caused the event.
mouseStateThe combination of mouse buttons that were pressed at the time the event was sent.
keyboardStateKeyboard modifiers for the event.

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.

[signal] void QVncServer::wheelEventReceived(const QPointF &mousePosition, const QPoint &angleDelta, Qt::KeyboardModifiers keyboardState)

Emitted when a wheel event is received.

mousePositionMouse position for the event.
angleDeltaThe relative amount of wheel rotation in eights of a degree.
keyboardStateKeyboard modifiers for the event.

See also QWheelEvent.

Available under certain Qt licenses.
Find out more.