QXmpp  Version: 1.4.0
Public Types | Public Slots | Signals | Public Member Functions | Properties | Friends | List of all members
QXmppClient Class Reference

The QXmppClient class is the main class for using QXmpp. More...

#include <QXmppClient.h>

Inheritance diagram for QXmppClient:
Inheritance graph
Collaboration diagram for QXmppClient:
Collaboration graph

Public Types

enum  Error { NoError , SocketError , KeepAliveError , XmppStreamError }
enum  State { DisconnectedState , ConnectingState , ConnectedState }
 This enumeration describes a client state. More...
enum  StreamManagementState { NoStreamManagement , NewStream , ResumedStream }
 Describes the use of XEP-0198: Stream Management. More...

Public Slots

void connectToServer (const QXmppConfiguration &, const QXmppPresence &initialPresence=QXmppPresence())
void connectToServer (const QString &jid, const QString &password)
void disconnectFromServer ()
bool sendPacket (const QXmppStanza &)
void sendMessage (const QString &bareJid, const QString &message)


void connected ()
void disconnected ()
 This signal is emitted when the XMPP connection disconnects.
void error (QXmppClient::Error)
void loggerChanged (QXmppLogger *logger)
 This signal is emitted when the logger changes.
void messageReceived (const QXmppMessage &message)
void presenceReceived (const QXmppPresence &presence)
void iqReceived (const QXmppIq &iq)
void sslErrors (const QList< QSslError > &errors)
void stateChanged (QXmppClient::State state)
 This signal is emitted when the client state changes.
- Signals inherited from QXmppLoggable
void setGauge (const QString &gauge, double value)
 Sets the given gauge to value.
void logMessage (QXmppLogger::MessageType type, const QString &msg)
 This signal is emitted to send logging messages.
void updateCounter (const QString &counter, qint64 amount=1)
 Updates the given counter by amount.

Public Member Functions

 QXmppClient (QObject *parent=nullptr)
 ~QXmppClient () override
bool addExtension (QXmppClientExtension *extension)
bool insertExtension (int index, QXmppClientExtension *extension)
bool removeExtension (QXmppClientExtension *extension)
QList< QXmppClientExtension * > extensions ()
template<typename T >
T * findExtension ()
 Returns the extension which can be cast into type T*, or 0 if there is no such extension. More...
template<typename T >
int indexOfExtension ()
 Returns the index of an extension. More...
bool isAuthenticated () const
 Returns true if the client has authenticated with the XMPP server.
bool isConnected () const
bool isActive () const
void setActive (bool active)
StreamManagementState streamManagementState () const
QXmppPresence clientPresence () const
void setClientPresence (const QXmppPresence &presence)
QXmppConfigurationconfiguration ()
QXmppLoggerlogger () const
 Returns the QXmppLogger associated with the current QXmppClient.
void setLogger (QXmppLogger *logger)
 Sets the QXmppLogger associated with the current QXmppClient.
QAbstractSocket::SocketError socketError ()
QString socketErrorString () const
 Returns the human-readable description of the last socket error if error() is QXmppClient::SocketError.
State state () const
 Returns the client's current state.
QXmppStanza::Error::Condition xmppStreamError ()
 Returns the XMPP stream error if QXmppClient::Error is QXmppClient::XmppStreamError.
QXmppRosterManagerrosterManager ()
QXmppVCardManagervCardManager ()
QXmppVersionManagerversionManager ()
- Public Member Functions inherited from QXmppLoggable
 QXmppLoggable (QObject *parent=nullptr)


 The QXmppLogger associated with the current QXmppClient.
State state
 The client's current state.


class QXmppInternalClientExtension

Additional Inherited Members

- Protected Member Functions inherited from QXmppLoggable
void debug (const QString &message)
void info (const QString &message)
void warning (const QString &message)
void logReceived (const QString &message)
void logSent (const QString &message)

Detailed Description

The QXmppClient class is the main class for using QXmpp.

It provides the user all the required functionality to connect to the server and perform operations afterwards.

This class will provide the handle/reference to QXmppRosterManager (roster management), QXmppVCardManager (vCard manager), and QXmppVersionManager (software version information).

By default, the client will automatically try reconnecting to the server. You can change that behaviour using QXmppConfiguration::setAutoReconnectionEnabled().

Not all the managers or extensions have been enabled by default. One can enable/disable the managers using the functions addExtension() and removeExtension(). findExtension() can be used to find a reference/pointer to a particular instantiated and enabled manager.

List of managers enabled by default:

Member Enumeration Documentation

◆ Error

An enumeration for type of error. Error could come due a TCP socket or XML stream or due to various stanzas.


No error.


Error due to TCP socket.


Error due to no response to a keep alive.


Error due to XML stream.

◆ State

This enumeration describes a client state.


Disconnected from the server.


Trying to connect to the server.


Connected to the server.

◆ StreamManagementState

Describes the use of XEP-0198: Stream Management.


Stream Management is not used.


Stream Management is used and the previous stream has not been resumed.


Stream Management is used and the previous stream has been resumed.

Constructor & Destructor Documentation

◆ QXmppClient()

QXmppClient::QXmppClient ( QObject *  parent = nullptr)

Creates a QXmppClient object.

parentis passed to the QObject's constructor. The default value is 0.

◆ ~QXmppClient()

QXmppClient::~QXmppClient ( )

Destructor, destroys the QXmppClient object.

Member Function Documentation

◆ addExtension()

bool QXmppClient::addExtension ( QXmppClientExtension extension)

Registers a new extension with the client.


◆ clientPresence()

QXmppPresence QXmppClient::clientPresence ( ) const

Returns the client's current presence.

◆ configuration()

QXmppConfiguration & QXmppClient::configuration ( )

Returns a modifiable reference to the current configuration of QXmppClient.

Reference to the QXmppClient's configuration for the connection.

◆ connected

void QXmppClient::connected ( )

This signal is emitted when the client connects successfully to the XMPP server i.e. when a successful XMPP connection is established. XMPP Connection involves following sequential steps:

  • TCP socket connection
  • Client sends start stream
  • Server sends start stream
  • TLS negotiation (encryption)
  • Authentication
  • Resource binding
  • Session establishment

After all these steps a successful XMPP connection is established and connected() signal is emitted.

After the connected() signal is emitted QXmpp will send the roster request to the server. On receiving the roster, QXmpp will emit QXmppRosterManager::rosterReceived(). After this signal, QXmppRosterManager object gets populated and you can use findExtension<QXmppRosterManager>() to get the handle of QXmppRosterManager object.

◆ connectToServer [1/2]

void QXmppClient::connectToServer ( const QString &  jid,
const QString &  password 

Overloaded function to simply connect to an XMPP server with a JID and password.

jidJID for the account.
passwordPassword for the account.

◆ connectToServer [2/2]

void QXmppClient::connectToServer ( const QXmppConfiguration config,
const QXmppPresence initialPresence = QXmppPresence() 

Attempts to connect to the XMPP server. Server details and other configurations are specified using the config parameter. Use signals connected(), error(QXmppClient::Error) and disconnected() to know the status of the connection.

configSpecifies the configuration object for connecting the XMPP server. This contains the host name, user, password etc. See QXmppConfiguration for details.
initialPresenceThe initial presence which will be set for this user after establishing the session. The default value is QXmppPresence::Available

◆ disconnectFromServer

void QXmppClient::disconnectFromServer ( )

Disconnects the client and the current presence of client changes to QXmppPresence::Unavailable and status text changes to "Logged out".

Make sure that the clientPresence is changed to QXmppPresence::Available, if you are again calling connectToServer() after calling the disconnectFromServer() function.

◆ error

void QXmppClient::error ( QXmppClient::Error  )

This signal is emitted when the XMPP connection encounters any error. The QXmppClient::Error parameter specifies the type of error occurred. It could be due to TCP socket or the xml stream or the stanza. Depending upon the type of error occurred use the respective get function to know the error.

◆ extensions()

QList< QXmppClientExtension * > QXmppClient::extensions ( )

Returns a list containing all the client's extensions.

◆ findExtension()

template<typename T >
T* QXmppClient::findExtension ( )

Returns the extension which can be cast into type T*, or 0 if there is no such extension.

Usage example:

QXmppDiscoveryManager* ext = client->findExtension<QXmppDiscoveryManager>();
//extension found, do stuff...
The QXmppDiscoveryManager class makes it possible to discover information about other entities as def...
Definition: QXmppDiscoveryManager.h:39

◆ indexOfExtension()

template<typename T >
int QXmppClient::indexOfExtension ( )

Returns the index of an extension.

Usage example:

int index = client->indexOfExtension<QXmppDiscoveryManager>();
if (index > 0) {
// extension found, do stuff...
} else {
// extension not found
QXmpp 1.2

◆ insertExtension()

bool QXmppClient::insertExtension ( int  index,
QXmppClientExtension extension 

Registers a new extension with the client at the given index.


◆ iqReceived

void QXmppClient::iqReceived ( const QXmppIq iq)

This signal is emitted when IQs of type result or error are received by the client and no registered QXmppClientExtension could handle it.

This is useful when it is only important to check whether the response of an IQ was successful. However, the recommended way is still to use an additional QXmppClientExtension for this kind of tasks.

◆ isActive()

bool QXmppClient::isActive ( ) const

Returns true if the current client state is "active", false if it is "inactive". See XEP-0352: Client State Indication for details.

On connect this is always reset to true.

QXmpp 1.0

◆ isConnected()

bool QXmppClient::isConnected ( ) const

Returns true if the client is connected to the XMPP server.

◆ messageReceived

void QXmppClient::messageReceived ( const QXmppMessage message)

Notifies that an XMPP message stanza is received. The QXmppMessage parameter contains the details of the message sent to this client. In other words whenever someone sends you a message this signal is emitted.

◆ presenceReceived

void QXmppClient::presenceReceived ( const QXmppPresence presence)

Notifies that an XMPP presence stanza is received. The QXmppPresence parameter contains the details of the presence sent to this client. This signal is emitted when someone login/logout or when someone's status changes Busy, Idle, Invisible etc.

◆ removeExtension()

bool QXmppClient::removeExtension ( QXmppClientExtension extension)

Unregisters the given extension from the client. If the extension is found, it will be destroyed.


◆ rosterManager()

QXmppRosterManager & QXmppClient::rosterManager ( )

Returns the reference to QXmppRosterManager object of the client.

Reference to the roster object of the connected client. Use this to get the list of friends in the roster and their presence information.
This method is deprecated since QXmpp 1.1. Use QXmppClient::findExtension<QXmppRosterManager>() instead.

◆ sendMessage

void QXmppClient::sendMessage ( const QString &  bareJid,
const QString &  message 

Utility function to send message to all the resources associated with the specified bareJid. If there are no resources available, that is the contact is offline or not present in the roster, it will still send a message to the bareJid.

Usage of this method is discouraged because most modern clients use carbon messages (XEP-0280: Message Carbons) and MAM (XEP-0313: Message Archive Management) and so could possibly receive messages multiple times or not receive them at all. QXmppClient::sendPacket() should be used instead with a QXmppMessage.
bareJidbareJid of the receiving entity
messageMessage string to be sent.

◆ sendPacket

bool QXmppClient::sendPacket ( const QXmppStanza packet)

After successfully connecting to the server use this function to send stanzas to the server. This function can solely be used to send various kind of stanzas to the server. QXmppStanza is a parent class of all the stanzas QXmppMessage, QXmppPresence, QXmppIq, QXmppBind, QXmppRosterIq, QXmppSession and QXmppVCard.

Returns true if the packet was sent, false otherwise.

Following code snippet illustrates how to send a message using this function:

QXmppMessage message(from, to, message);
The QXmppMessage class represents an XMPP message.
Definition: QXmppMessage.h:46
packetA valid XMPP stanza. It can be an iq, a message or a presence stanza.

◆ setActive()

void QXmppClient::setActive ( bool  active)

Sets the client state as described in XEP-0352: Client State Indication.

On connect this is always reset to true.

QXmpp 1.0

◆ setClientPresence()

void QXmppClient::setClientPresence ( const QXmppPresence presence)

Changes the presence of the connected client.

The connection to the server will be updated accordingly:

  • Otherwise, the connection to the server will be established as needed.
presenceQXmppPresence object

◆ socketError()

QAbstractSocket::SocketError QXmppClient::socketError ( )

Returns the socket error if error() is QXmppClient::SocketError.

◆ sslErrors

void QXmppClient::sslErrors ( const QList< QSslError > &  errors)

This signal is emitted to indicate that one or more SSL errors were encountered while establishing the identity of the server.

◆ streamManagementState()

QXmppClient::StreamManagementState QXmppClient::streamManagementState ( ) const

Returns the current XEP-0198: Stream Management state of the connection.

Upon connection of the client this can be used to check whether the previous stream has been resumed.

QXmpp 1.4

◆ vCardManager()

QXmppVCardManager & QXmppClient::vCardManager ( )

Returns the reference to QXmppVCardManager, implementation of XEP-0054. http://xmpp.org/extensions/xep-0054.html

This method is deprecated since QXmpp 1.1. Use QXmppClient::findExtension<QXmppVCardManager>() instead.

◆ versionManager()

QXmppVersionManager & QXmppClient::versionManager ( )

Returns the reference to QXmppVersionManager, implementation of XEP-0092. http://xmpp.org/extensions/xep-0092.html

This method is deprecated since QXmpp 1.1. Use QXmppClient::findExtension<QXmppVersionManager>() instead.

The documentation for this class was generated from the following files: