QXmpp

Introduction

QXmpp is a cross-platform C++ XMPP client and server library built on top of the Qt framework (Qt 6.4+). It implements a large number of XMPP Extension Protocols (XEPs) and exposes a modern, reactive API based on C++20 and Qt's property system.

Getting Started

The central class is QXmppClient. Create one, register the managers you need, then connect:

 auto *client = new QXmppClient(this);

 // Register managers
 auto *pubsub  = client->addNewExtension<QXmppPubSubManager>();
 auto *disco   = client->addNewExtension<QXmppDiscoveryManager>();
 auto *muc     = client->addNewExtension<QXmppMucManagerV2>();

 // Connect
 QXmppConfiguration config;
 config.setJid("user@example.org");
 config.setPassword("secret");
 client->connectToServer(config);

Async API

All network operations return a QXmppTask<T>, which represents a pending result. QXmppTask supports co_await, making sequential async code straightforward:

 QXmppTask<void> MyManager::doSomething()
 {
     auto result = co_await muc->joinRoom("room@conference.example.org", "MyNick").withContext(this);
     if (auto *err = std::get_if<QXmppError>(&result)) {
         qWarning() << "Join failed:" << err->description;
         co_return;
     }
     // continue ...
 }

Alternatively, use .then() to attach a callback:

 muc->joinRoom("room@conference.example.org", "MyNick").then(this, [](auto result) {
     if (auto *err = std::get_if<QXmppError>(&result)) {
         qWarning() << "Join failed:" << err->description;
     }
 });

Results are typically QXmpp::Result<T>, a std::variant<T, QXmppError>. Always pass a context object (this) to .then() or .withContext() to ensure the callback is not invoked after the object has been destroyed.

Reactive Properties

Selected APIs expose observable state via QBindable<T>, backed by Qt's QProperty system. QXmppMucRoomV2 is the primary example — room info, config, and participant state are all exposed as bindable properties that update automatically when the server reports changes:

 auto room = muc->room("room@conference.example.org");
 room.setWatchAvatar(true);

 auto avatar = room.avatar();
 avatar.addNotifier([avatar]() {
     // called whenever the room avatar changes
     auto val = avatar.value();
 });

Managers

Managers are the primary way to use XMPP features. Register them with QXmppClient and extend QXmppClient by subclassing QXmppClientExtension. See the Managers module for the full list.

Messaging

Contacts and Roster

Groupchat

File Sharing

End-to-End Encryption

Calls

Bookmarks and PubSub

Service Discovery and Utilities

Legacy (deprecated)

  • QXmppMucManager — superseded by QXmppMucManagerV2
  • QXmppCarbonManager — superseded by QXmppCarbonManagerV2
  • QXmppBookmarkManager — superseded by QXmppPepBookmarkManager
  • QXmppArchiveManager — superseded by QXmppMamManager
  • QXmppRpcManager — RPC (XEP-0009)

Low-Level Stanza API

For direct access to XMPP stanzas:

  • QXmppIq
  • QXmppMessage
  • QXmppPresence