Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlnotifier.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6#include <QtCore/qdebug.h>
7#include <private/qthread_p.h>
8
10
11typedef void (*Callback)(QQmlNotifierEndpoint *, void **);
12
19
29
30namespace {
31 struct NotifyListTraversalData {
32 NotifyListTraversalData(QQmlNotifierEndpoint *ep = nullptr)
33 : originalSenderPtr(0)
34 , disconnectWatch(nullptr)
35 , endpoint(ep)
36 {}
37
38 qintptr originalSenderPtr;
39 qintptr *disconnectWatch;
40 QQmlNotifierEndpoint *endpoint;
41 };
42}
43
44void QQmlNotifier::notify(QQmlData *ddata, int notifierIndex)
45{
46 if (QQmlNotifierEndpoint *ep = ddata->notify(notifierIndex))
47 emitNotify(ep, nullptr);
48}
49
50void QQmlNotifier::emitNotify(QQmlNotifierEndpoint *endpoint, void **a)
51{
52 QVarLengthArray<NotifyListTraversalData> stack;
53 while (endpoint) {
54 stack.append(NotifyListTraversalData(endpoint));
55 endpoint = endpoint->next;
56 }
57
58 int i = 0;
59 for (; i < stack.size(); ++i) {
60 NotifyListTraversalData &data = stack[i];
61
62 if (!data.endpoint->isNotifying()) {
63 data.endpoint->startNotifying(&data.originalSenderPtr);
64 data.disconnectWatch = &data.originalSenderPtr;
65 } else {
66 data.disconnectWatch = (qintptr *)(data.endpoint->senderPtr & ~0x1);
67 }
68 }
69
70 while (--i >= 0) {
71 NotifyListTraversalData &data = stack[i];
72 if (*data.disconnectWatch) {
73 Q_ASSERT(QQmlNotifier_callbacks[data.endpoint->callback]);
74 QQmlNotifier_callbacks[data.endpoint->callback](data.endpoint, a);
75 if (data.disconnectWatch == &data.originalSenderPtr && data.originalSenderPtr) {
76 data.endpoint->stopNotifying(&data.originalSenderPtr);
77 }
78 }
79 }
80}
81
82/*! \internal
83 \a sourceSignal MUST be in the signal index range (see QObjectPrivate::signalIndex()).
84 This is different from QMetaMethod::methodIndex().
85*/
86void QQmlNotifierEndpoint::connect(QObject *source, int sourceSignal, QQmlEngine *engine, bool doNotify)
87{
89
90 Q_ASSERT(engine);
91 if (QObjectPrivate::get(source)->threadData.loadRelaxed()->threadId.loadRelaxed() !=
92 QObjectPrivate::get(engine)->threadData.loadRelaxed()->threadId.loadRelaxed()) {
93
94 QString sourceName;
95 QDebug(&sourceName) << source;
96 sourceName = sourceName.left(sourceName.size() - 1);
97 QString engineName;
98 QDebug(&engineName).nospace() << engine;
99 engineName = engineName.left(engineName.size() - 1);
100
101 qFatal("QQmlEngine: Illegal attempt to connect to %s that is in"
102 " a different thread than the QML engine %s.", qPrintable(sourceName),
103 qPrintable(engineName));
104 }
105
106 setSender(qintptr(source));
107 this->sourceSignal = sourceSignal;
108 QQmlPropertyPrivate::flushSignal(source, sourceSignal);
109 QQmlData *ddata = QQmlData::get(source, true);
110 ddata->addNotify(sourceSignal, this);
111 if (doNotify) {
112 needsConnectNotify = doNotify;
113 QObjectPrivate * const priv = QObjectPrivate::get(source);
114 priv->connectNotify(QMetaObjectPrivate::signal(source->metaObject(), sourceSignal));
115 }
116}
117
118QT_END_NAMESPACE
Combined button and popup list for selecting options.
void QQmlUnbindableToUnbindableGuard_callback(QQmlNotifierEndpoint *, void **)
void QQmlVMEMetaObjectEndpoint_callback(QQmlNotifierEndpoint *, void **)
void QQmlBoundSignal_callback(QQmlNotifierEndpoint *, void **)
void QQmlUnbindableToBindableGuard_callback(QQmlNotifierEndpoint *, void **)
QT_BEGIN_NAMESPACE typedef void(* Callback)(QQmlNotifierEndpoint *, void **)
void QQmlDirtyReferenceObject_callback(QQmlNotifierEndpoint *, void **)
void QQmlJavaScriptExpressionGuard_callback(QQmlNotifierEndpoint *, void **)
static Callback QQmlNotifier_callbacks[]