D-Bus signals cause segmentation faults
-
Hi there,
I am trying to communicate with NetworkManager, a D-Bus service. While calling methods and reading properties is just fine, listening to signals is causing trouble, or more precisely, segmentation faults.
The following simplified code listens to StateChanged() signals, which are emitted when NetworkManager detects that the network connection was established or lost:
networkmanagerproxy.h:
@#ifndef NETWORKMANAGERPROXY_H
#define NETWORKMANAGERPROXY_H#include <QDBusInterface>
class NetworkManagerProxy : public QDBusInterface
{
Q_OBJECTpublic:
NetworkManagerProxy();Q_SIGNALS:
void StateChanged(uint u);public Q_SLOTS:
void stateChanged(uint u);
};
#endif // NETWORKMANAGERPROXY_H
@networkmanagerproxy.cpp:
@#include "networkmanagerproxy.h"
#include <QDebug>NetworkManagerProxy::NetworkManagerProxy() : QDBusInterface("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager",
QDBusConnection::systemBus())
{
connection().connect(service(), path(), interface(), "StateChanged", this, SLOT(stateChanged(uint)));
};void NetworkManagerProxy::stateChanged(uint u)
{
qDebug() << "STATE CHANGED: " << u;
}@main.cpp:
@#include "networkmanagerproxy.h"
#include <QCoreApplication>int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
new NetworkManagerProxy();
app.exec();
}@Running this code and removing all network connectivity while it runs crashes it on Ubuntu 10.04 (Qt 4.6.2), while it works on Ubuntu 11.04 (Qt 4.7.2). It has to run on 10.04 though. "STATE CHANGED" is not printed, but crash occurs upon disabling NetworkManager, meaning it is the signal that is killing this application. Stacktrace looks like this:
@(gdb) bt
#0 QString (t=0x6371b0) at ../../include/QtCore/../../src/corelib/tools/qstring.h:715
#1 QDBusObjectPath (t=0x6371b0) at ../../include/QtDBus/../../src/dbus/qdbusextratypes.h:61
#2 qMetaTypeConstructHelper<QDBusObjectPath> (t=0x6371b0) at ../../include/QtCore/../../src/corelib/kernel/qmetatype.h:138
#3 0x00007ffff68941ff in QMetaType::construct (type=<value optimized out>, copy=0x6371b0) at kernel/qmetatype.cpp:1116
#4 0x00007ffff68a9dec in construct (x=0x7fffffffdf10, copy=0x6371b0) at kernel/qvariant.cpp:177
#5 0x00007ffff70cf0ad in construct (x=0x7fffffffdf10, copy=0x6371b0) at kernel/qguivariant.cpp:182
#6 0x00007ffff68a6a7f in QVariant (this=0x7ffff5d4ce40, typeOrUserType=8, copy=0x1) at kernel/qvariant.cpp:1635
#7 0x00007ffff7b9d202 in QDBusInterfacePrivate::metacall (this=<value optimized out>, c=<value optimized out>, id=<value optimized out>,
argv=<value optimized out>) at qdbusinterface.cpp:289
#8 0x000000000040cbab in NetworkManagerProxy::qt_metacall (this=0x61da30, _c=QMetaObject::InvokeMetaMethod, _id=6, _a=0x7fffffffe210)
at moc_networkmanagerproxy.cpp:71
#9 0x00007ffff7b88486 in QDBusConnectionPrivate::deliverCall (this=<value optimized out>, object=<value optimized out>,
msg=<value optimized out>, metaTypes=..., slotIdx=<value optimized out>) at qdbusintegrator.cpp:904
#10 0x00007ffff7b9305f in QDBusCallDeliveryEvent::placeMetaCall(QObject*) () from /usr/lib/libQtDBus.so.4
#11 0x00007ffff6899d49 in QObject::event (this=0x61da30, e=0x64e070) at kernel/qobject.cpp:1248
#12 0x00007ffff688a06c in QCoreApplication::notifyInternal (this=0x7fffffffe7b0, receiver=0x61da30, event=0x64e070)
at kernel/qcoreapplication.cpp:704
#13 0x00007ffff688c7e7 in QCoreApplication::sendEvent (receiver=0x0, event_type=<value optimized out>, data=0x614490)
at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:215
#14 QCoreApplicationPrivate::sendPostedEvents (receiver=0x0, event_type=<value optimized out>, data=0x614490)
at kernel/qcoreapplication.cpp:1345
#15 0x00007ffff68b39d3 in QCoreApplication::sendPostedEvents (s=<value optimized out>)
at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:220
#16 postEventSourceDispatch (s=<value optimized out>) at kernel/qeventdispatcher_glib.cpp:276
#17 0x00007ffff50988c2 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#18 0x00007ffff509c748 in ?? () from /lib/libglib-2.0.so.0
#19 0x00007ffff509c8fc in g_main_context_iteration () from /lib/libglib-2.0.so.0
#20 0x00007ffff68b3513 in QEventDispatcherGlib::processEvents (this=0x619bd0, flags=<value optimized out>)
at kernel/qeventdispatcher_glib.cpp:412
#21 0x00007ffff6888992 in QEventLoop::processEvents (this=<value optimized out>, flags=DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece.
) at kernel/qeventloop.cpp:149
#22 0x00007ffff6888d6c in QEventLoop::exec (this=0x7fffffffe750, flags=DWARF-2 expression error: DW_OP_reg operations must be used either alone or in conjuction with DW_OP_piece.
) at kernel/qeventloop.cpp:201
#23 0x00007ffff688caab in QCoreApplication::exec () at kernel/qcoreapplication.cpp:981
#24 0x000000000040c77c in main (argc=1, argv=0x7fffffffe8c8) at main.cpp:9@I wonder whether I missed something about using D-Bus signals that prevents this from running. qdbusviewer basically does something similar, after all.
Note: I use QDBusConnection::connect() instead of QObject::connect(), because the latter always causes crashing, even in 11.04.