Logo Search packages:      
Sourcecode: kdbus version File versions  Download package

QDBusConnection QDBusConnection::addConnection ( BusType  type,
const QString &  name = default_connection_name 
) [static]

Add a connection to a bus with a specific bus type.

This is a factory method as it will create a connection for the given name if its not available yet, but return a previously created connection for that name if available.

Depending on the BusType the DBus library will connect to the address configured for that type, so this is the recommended way to create connection to DBus.

   // Associate the default connection name with a connection to the user's
   // session bus
   QDBusConnection con = QDBusConnection::addConnection(QDBusConnection::SessionBus);

   // check if we are connected and which uniqueName we got
   if (con.isConnected())
   {
       qDebug("Connected to session bus. We got uniqueName %s",
              con.uniqueName().local8Bit().data());
   }

Parameters:
type the BusType of the bus to connect to
name the name to use for QDBusConnection's connection sharing
Returns:
a connection handle. Check isConnected() to find out if the connection attempt has been successfull
See also:
closeConnection()

Definition at line 181 of file qdbusconnection.cpp.

References QDBusConnection(), SessionBus, and SystemBus.

Referenced by DBusTreeWidget::initObjects().

{
//    Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection",
//               "Cannot create connection without a Q[Core]Application instance");

    QDBusConnectionPrivate *d = manager()->connection(name);
    if (d)
        return QDBusConnection(name);

    d = new QDBusConnectionPrivate;
    DBusConnection *c = 0;
    switch (type) {
        case SystemBus:
            c = dbus_bus_get(DBUS_BUS_SYSTEM, &d->error);
            break;
        case SessionBus:
            c = dbus_bus_get(DBUS_BUS_SESSION, &d->error);
            break;
        case ActivationBus:
            c = dbus_bus_get(DBUS_BUS_STARTER, &d->error);
            break;
    }
    d->setConnection(c); //setConnection does the error handling for us

    manager()->setConnection(name, d);

    return QDBusConnection(name);
}


Generated by  Doxygen 1.6.0   Back to index