QObject: Extend debug output of connect
Sometimes it is hard to find the line, when the warning "QObject::connect: invalid null parameter" appears in the log. This change adds the class names of the sender and receiver to give a hint where to search for the wrong call to connect. Change-Id: I00cead7d943f96d60f198cb3f0bed34ba10285c5 Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
parent
0dd2973761
commit
c08197ccab
@ -4802,7 +4802,12 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s
|
||||
const int *types, const QMetaObject *senderMetaObject)
|
||||
{
|
||||
if (!sender || !receiver || !slotObj || !senderMetaObject) {
|
||||
qWarning("QObject::connect: invalid null parameter");
|
||||
const char *senderString = sender ? sender->metaObject()->className()
|
||||
: senderMetaObject ? senderMetaObject->className()
|
||||
: "Unknown";
|
||||
const char *receiverString = receiver ? receiver->metaObject()->className()
|
||||
: "Unknown";
|
||||
qWarning("QObject::connect(%s, %s): invalid null parameter", senderString, receiverString);
|
||||
if (slotObj)
|
||||
slotObj->destroyIfLastRef();
|
||||
return QMetaObject::Connection();
|
||||
|
@ -145,6 +145,7 @@ private slots:
|
||||
void disconnectDoesNotLeakFunctor();
|
||||
void contextDoesNotLeakFunctor();
|
||||
void connectBase();
|
||||
void connectWarnings();
|
||||
void qmlConnect();
|
||||
void exceptions();
|
||||
void noDeclarativeParentChangedOnDestruction();
|
||||
@ -6685,6 +6686,26 @@ void tst_QObject::connectBase()
|
||||
QCOMPARE( r1.count_slot3, 1 );
|
||||
}
|
||||
|
||||
void tst_QObject::connectWarnings()
|
||||
{
|
||||
SubSender sub;
|
||||
SenderObject obj;
|
||||
ReceiverObject r1;
|
||||
r1.reset();
|
||||
|
||||
QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): invalid null parameter");
|
||||
connect(nullptr, &SubSender::signal1, &r1, &ReceiverObject::slot1);
|
||||
|
||||
QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SubSender, Unknown): invalid null parameter");
|
||||
connect(&sub, &SubSender::signal1, nullptr, &ReceiverObject::slot1);
|
||||
|
||||
QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): invalid null parameter");
|
||||
connect(nullptr, &SenderObject::signal1, &r1, &ReceiverObject::slot1);
|
||||
|
||||
QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, Unknown): invalid null parameter");
|
||||
connect(&obj, &SenderObject::signal1, nullptr, &ReceiverObject::slot1);
|
||||
}
|
||||
|
||||
struct QmlReceiver : public QtPrivate::QSlotObjectBase
|
||||
{
|
||||
int callCount;
|
||||
|
Loading…
Reference in New Issue
Block a user