• UpnpDiscovery
  • UpnpDiscovery Class

    Allows to discover UPnP devices in the network. More...

    Header: #include <UpnpDiscovery>
    Inherits: HardwareResource
    Inherited By:


    Public Functions

    UpnpDiscovery(QObject * parent = nullptr)
    virtual ~UpnpDiscovery()
    virtual UpnpDiscoveryReply * discoverDevices(const QString & searchTarget = "ssdp:all", const QString & userAgent = QString(), const int & timeout = 5000) = 0
    virtual void sendToMulticast(const QByteArray & data) = 0


    void upnpNotify(const QByteArray & notifyMessage)

    Additional Inherited Members

    Detailed Description

    Allows to discover UPnP devices in the network.

    This resource allows plugins to discover UPnP devices in the network and receive notification messages. The resource will bind a UDP socket to the multicast on port 1900.

    The communication was implementet using following documentation: http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf


    In order to perform an UPnP discovery in your plugin, you can take a look at following example:


    class DevicePluginExample : public DevicePlugin
        void discoverUpnpDevices();
    private slots:
        void onUpnpDiscoveryFinished();


    #include "network/upnp/upnpdiscovery.h"
    #include "network/upnp/upnpdiscoveryreply.h"
    void DevicePluginExample::discoverUpnpDevices() {
        UpnpDiscoveryReply *reply = hardwareManager()->upnpDiscovery()->discoverDevices();
        connect(reply, &UpnpDiscoveryReply::finished, this, &DevicePluginExample::onUpnpDiscoveryFinished);
    void DevicePluginExample::onUpnpDiscoveryFinished() {
        UpnpDiscoveryReply *reply = static_cast<UpnpDiscoveryReply *>(sender());
        if (reply->error() != UpnpDiscoveryReply::UpnpDiscoveryReplyErrorNoError) {
            qCWarning(dcExample()) << "UPnP discovery error" << reply->error();
        // Note: you have to delete the reply using deleteLater()
        foreach (const UpnpDeviceDescriptor &upnpDevice, reply->deviceDescriptors()) {
            qCDebug(dcExample()) << upnpDevice.friendlyName() << upnpDevice.hostAddress().toString();

    See also UpnpDevice and UpnpDeviceDescriptor.

    Member Function Documentation

    UpnpDiscovery::UpnpDiscovery(QObject * parent = nullptr)

    Construct the hardware resource UpnpDiscovery with the given parent.

    [virtual] UpnpDiscovery::~UpnpDiscovery()

    Destroys this UpnpDiscovery.

    [pure virtual] UpnpDiscoveryReply * UpnpDiscovery::discoverDevices(const QString & searchTarget = "ssdp:all", const QString & userAgent = QString(), const int & timeout = 5000)

    Start a UPnP discovery request for devices listening on the given searchTarget and userAgent. The discovery duration can be specified with timeout parameter.

    [pure virtual] void UpnpDiscovery::sendToMulticast(const QByteArray & data)

    Sends data to the UpnP multicast group. This method can be used in order to send raw data to the group.

    [signal] void UpnpDiscovery::upnpNotify(const QByteArray & notifyMessage)

    This signal will be emitted when a UPnP NOTIFY message notifyMessage will be recognized.