QObject: fix connection to function pointer with non-copyable references argument
For example, QObject is non copyable (its copy constructor is deleted or private via Q_DISABLE_COPY). It should still be allowed to pass a reference to a QObject as an argument to as signal (or slot). This fixes a compilation failure. Task-number: QTBUG-36119 Change-Id: I9bcf477e347d69fdae2543c99781b6421883be78 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
04b8af2739
commit
e59b28e08e
@ -567,9 +567,9 @@ namespace QtPrivate {
|
|||||||
Q_STATIC_ASSERT(CheckCompatibleArguments<FunctionPointer<Signal>::Arguments, FunctionPointer<Slot>::Arguments>::value)
|
Q_STATIC_ASSERT(CheckCompatibleArguments<FunctionPointer<Signal>::Arguments, FunctionPointer<Slot>::Arguments>::value)
|
||||||
*/
|
*/
|
||||||
template<typename A1, typename A2> struct AreArgumentsCompatible {
|
template<typename A1, typename A2> struct AreArgumentsCompatible {
|
||||||
static int test(A2);
|
static int test(const typename RemoveRef<A2>::Type&);
|
||||||
static char test(...);
|
static char test(...);
|
||||||
static A1 dummy();
|
static const typename RemoveRef<A1>::Type &dummy();
|
||||||
enum { value = sizeof(test(dummy())) == sizeof(int) };
|
enum { value = sizeof(test(dummy())) == sizeof(int) };
|
||||||
};
|
};
|
||||||
template<typename A1, typename A2> struct AreArgumentsCompatible<A1, A2&> { enum { value = false }; };
|
template<typename A1, typename A2> struct AreArgumentsCompatible<A1, A2&> { enum { value = false }; };
|
||||||
|
@ -4759,6 +4759,9 @@ class LotsOfSignalsAndSlots: public QObject
|
|||||||
#endif*/
|
#endif*/
|
||||||
static void static_slot_vPFvvE(fptr) {}
|
static void static_slot_vPFvvE(fptr) {}
|
||||||
|
|
||||||
|
void slot_vcRQObject(const QObject &) {}
|
||||||
|
void slot_vRQObject(QObject &) {}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void signal_v();
|
void signal_v();
|
||||||
void signal_vi(int);
|
void signal_vi(int);
|
||||||
@ -4776,6 +4779,9 @@ class LotsOfSignalsAndSlots: public QObject
|
|||||||
void const_signal_v() const;
|
void const_signal_v() const;
|
||||||
void const_signal_vi(int) const;
|
void const_signal_vi(int) const;
|
||||||
|
|
||||||
|
void signal_vcRQObject(const QObject &);
|
||||||
|
void signal_vRQObject(QObject &);
|
||||||
|
|
||||||
void signal(short&, short, long long, short);
|
void signal(short&, short, long long, short);
|
||||||
void otherSignal(const char *);
|
void otherSignal(const char *);
|
||||||
};
|
};
|
||||||
@ -4893,6 +4899,14 @@ void tst_QObject::connectCxx0xTypeMatching()
|
|||||||
QVERIFY(QObject::connect(&obj, &Foo::const_signal_vi, &obj, &Foo::slot_vi));
|
QVERIFY(QObject::connect(&obj, &Foo::const_signal_vi, &obj, &Foo::slot_vi));
|
||||||
QVERIFY(QObject::connect(&obj, &Foo::signal_vi, &obj, &Foo::const_slot_vi));
|
QVERIFY(QObject::connect(&obj, &Foo::signal_vi, &obj, &Foo::const_slot_vi));
|
||||||
QVERIFY(QObject::connect(&obj, &Foo::signal_vi, &obj, &Foo::const_slot_v));
|
QVERIFY(QObject::connect(&obj, &Foo::signal_vi, &obj, &Foo::const_slot_v));
|
||||||
|
|
||||||
|
QVERIFY(QObject::connect(&obj, &Foo::signal_vcRQObject, &obj, &Foo::slot_vcRQObject));
|
||||||
|
QVERIFY(QObject::connect(&obj, &Foo::signal_vRQObject, &obj, &Foo::slot_vRQObject));
|
||||||
|
QVERIFY(QObject::connect(&obj, &Foo::signal_vRQObject, &obj, &Foo::slot_vcRQObject));
|
||||||
|
// QVERIFY(QObject::connect(&obj, &Foo::signal_vcRQObject, &obj, &Foo::slot_vRQObject)); // Should be an error (const& -> &)
|
||||||
|
|
||||||
|
QVERIFY(QObject::connect(&obj, &Foo::signal_vRi, &obj, &Foo::slot_vs));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StringVariant : public QObject
|
class StringVariant : public QObject
|
||||||
|
Loading…
Reference in New Issue
Block a user