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 <thiago.macieira@intel.com>
(cherry picked from commit 6ea2a12e27ecf5ab2190c33ca66ab08f23c72350)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
David Faure 2023-11-21 12:40:56 +01:00 committed by Qt Cherry-pick Bot
parent 90b033d777
commit 66c0f88ff6
3 changed files with 16 additions and 1 deletions

View File

@ -631,6 +631,7 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
const QString &signature_, QList<QMetaType> &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;
}

View File

@ -4,6 +4,7 @@
#include <QCoreApplication>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QLoggingCategory>
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);

View File

@ -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