From 66c0f88ff631150c5512a61beff9aa94d57bf006 Mon Sep 17 00:00:00 2001 From: David Faure Date: Tue, 21 Nov 2023 12:40:56 +0100 Subject: [PATCH] QDBusConnection: output error message from findSlot This helps debugging why an adaptor's method fails to be called. Example output: QDBusConnection: couldn't handle call to LaunchCommand: Type not registered with QtDBus in parameter list: QByteArrayList tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall shows many warnings after this commit, since it's testing many cases of "no such slot". Pick-to: 6.1 6.0 5.15 Change-Id: Ic4ddcd91d005555a02d531fc8960aea2c809e20b Reviewed-by: Thiago Macieira (cherry picked from commit 6ea2a12e27ecf5ab2190c33ca66ab08f23c72350) Reviewed-by: Qt Cherry-pick Bot --- src/dbus/qdbusintegrator.cpp | 12 +++++++++++- tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp | 4 ++++ tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 20496290fe2..011436efd77 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -631,6 +631,7 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags, const QString &signature_, QList &metaTypes) { QByteArray msgSignature = signature_.toLatin1(); + QString parametersErrorMsg; for (int idx = mo->methodCount() - 1 ; idx >= QObject::staticMetaObject.methodCount(); --idx) { QMetaMethod mm = mo->method(idx); @@ -657,8 +658,10 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags, QString errorMsg; int inputCount = qDBusParametersForMethod(mm, metaTypes, errorMsg); - if (inputCount == -1) + if (inputCount == -1) { + parametersErrorMsg = errorMsg; continue; // problem parsing + } metaTypes[0] = returnType; bool hasMessage = false; @@ -720,6 +723,13 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags, } // no slot matched + if (!parametersErrorMsg.isEmpty()) { + qCWarning(dbusIntegration, "QDBusConnection: couldn't handle call to %s: %ls", + name.constData(), qUtf16Printable(parametersErrorMsg)); + } else { + qCWarning(dbusIntegration, "QDBusConnection: couldn't handle call to %s, no slot matched", + name.constData()); + } return -1; } diff --git a/tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp b/tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp index c5952c3b36f..52c1ee8fa17 100644 --- a/tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp +++ b/tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp @@ -4,6 +4,7 @@ #include #include #include +#include static const char serviceName[] = "org.qtproject.autotests.qpong"; static const char objectPath[] = "/org/qtproject/qpong"; @@ -32,6 +33,9 @@ int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); + // Silence many warnings from findSlot() about ping() not having the expected argument types + QLoggingCategory::setFilterRules("qt.dbus.integration=false"); + QDBusConnection con = QDBusConnection::sessionBus(); if (!con.isConnected()) exit(1); diff --git a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp index 39c88be1e69..0ca5d3e44e7 100644 --- a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp +++ b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp @@ -1145,6 +1145,7 @@ void tst_QDBusMarshall::receiveUnknownType() // now spin our event loop. We don't catch this call, so let's get the reply QEventLoop loop; QTimer::singleShot(200, &loop, SLOT(quit())); + QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: couldn't handle call to theSlot, no slot matched"); loop.exec(); // now try to receive the reply