QAbstractDeclarativeData::parentChanged = parentChanged;
QAbstractDeclarativeData::objectNameChanged = objectNameChanged;
QAbstractDeclarativeData::signalEmitted = signalEmitted;
+ QAbstractDeclarativeData::receivers = receivers;
}
static void destroyed(QAbstractDeclarativeData *, QObject *);
static void parentChanged(QAbstractDeclarativeData *, QObject *, QObject *);
static void objectNameChanged(QAbstractDeclarativeData *, QObject *);
static void signalEmitted(QAbstractDeclarativeData *, QObject *, int, void **);
+ static int receivers(QAbstractDeclarativeData *, const QObject *, int);
void destroyed(QObject *);
void parentChanged(QObject *, QObject *);
inline QQmlNotifierEndpoint *notify(int index);
void addNotify(int index, QQmlNotifierEndpoint *);
+ int endpointCount(int index);
// The context that created the C++ object
QQmlContextData *context;
if (ep) QQmlNotifier::emitNotify(ep);
}
+int QQmlData::receivers(QAbstractDeclarativeData *d, const QObject *, int index)
+{
+ return static_cast<QQmlData *>(d)->endpointCount(index);
+}
+
+int QQmlData::endpointCount(int index)
+{
+ int count = 0;
+ QQmlNotifierEndpoint *ep = notify(index);
+ if (!ep)
+ return count;
+ ++count;
+ while (ep->next) {
+ ++count;
+ ep = ep->next;
+ }
+ return count;
+}
+
void QQmlEnginePrivate::init()
{
Q_Q(QQmlEngine);
--- /dev/null
+import Test 1.0
+
+MyReceiversTestObject {
+ property int dummy: prop
+ onPropChanged: { var a = 0; } //do nothing
+ onMySignal: { var a = 0; } //do nothing
+}
+
qmlRegisterType<MyEnum1Class>("Test",1,0,"MyEnum1Class");
qmlRegisterType<MyEnum2Class>("Test",1,0,"MyEnum2Class");
qmlRegisterType<MyEnumDerivedClass>("Test",1,0,"MyEnumDerivedClass");
+
+ qmlRegisterType<MyReceiversTestObject>("Test",1,0,"MyReceiversTestObject");
}
QVariant myCustomVariantTypeConverter(const QString &data)
UnavailableType() {}
};
+class MyReceiversTestObject : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(int prop READ prop NOTIFY propChanged)
+public:
+ MyReceiversTestObject() {}
+
+ int prop() const { return 5; }
+
+ int mySignalCount() { return receivers(SIGNAL(mySignal())); }
+ int propChangedCount() { return receivers(SIGNAL(propChanged())); }
+
+signals:
+ void mySignal();
+ void propChanged();
+};
+
class MyDotPropertyObject : public QObject
{
Q_OBJECT
QML_DECLARE_TYPE(MyRevisionedClass)
QML_DECLARE_TYPE(MyRevisionedSubclass)
QML_DECLARE_TYPE(MySubclass)
+QML_DECLARE_TYPE(MyReceiversTestObject)
void registerTypes();
void nestedComponentRoots();
void registrationOrder();
void readonly();
+ void receivers();
void basicRemote_data();
void basicRemote();
delete o;
}
+void tst_qqmllanguage::receivers()
+{
+ QQmlComponent component(&engine, TEST_FILE("receivers.qml"));
+
+ MyReceiversTestObject *o = qobject_cast<MyReceiversTestObject*>(component.create());
+ QVERIFY(o != 0);
+ QCOMPARE(o->mySignalCount(), 1);
+ QCOMPARE(o->propChangedCount(), 2);
+
+ delete o;
+}
+
// QTBUG-18268
void tst_qqmllanguage::remoteLoadCrash()
{