Simple QtDBus question



  • Hi there,

    I'm trying to get some IPC going between a program called Mixxx (for DJing) and a separate application used to control Mixxx. I'm going to implement this via the DBus. I understand how the DBus works, but I'm having trouble connecting to it using Qt. I've been working with the DBus examples provided by Qt. In the chat example, there is this section of code in the main:

    [code]ChatMainWindow::ChatMainWindow()
    : m_nickname(QLatin1String("nickname"))
    {
    setupUi(this);

    // add our D-Bus interface and connect to D-Bus
    new ChatAdaptor(this);
    QDBusConnection::sessionBus().registerObject("/", this);

    com::trolltech::chat *iface;
    iface = new com::trolltech::chat(QString(), QString(), QDBusConnection::sessionBus(), this);
    //connect(iface, SIGNAL(message(QString,QString)), this, SLOT(messageSlot(QString,QString)));
    QDBusConnection::sessionBus().connect(QString(), QString(), "com.trolltech.chat", "message", this, SLOT(messageSlot(QString,QString)));
    connect(iface, SIGNAL(action(QString,QString)), this, SLOT(actionSlot(QString,QString)));

    }
    [/code]

    My question is that in the new ChatAdaptor(this) line, what would I use in the place of 'this' if I don't have any Qt GUI? I'm not that
    comfortable with programming yet so if anyone can answer this it would be great if as much detail as possible could be included, like what 'this' is
    in this context? Any help is very much appreciated.

    Thanks in advance!



  • Well, the ChatAdaptor object simply gets a parent object, I suppose. In the case you have posted, it is the ChatMainWindow widget. It does not need to be a QWidget inherited class, QObject is enough. Note how the pointer returned by "new ChatAdaptor(this)" is never stored anywhere. This is because the object will be deleted when the parent is deleted.
    In a non-GUI application, you can define a class inheriting QObject, and create the ChatAdaptor object and the QDBusConnections in it's constructor the same way. The QDBus functionality does not depend on the parent being a widget.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.