Qt 6.x
The Qt SDK
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
4#include "qqmlnotifier_p.h"
5#include "qqmlproperty_p.h"
6#include <QtCore/qdebug.h>
7#include <private/qthread_p.h>
8
10
11typedef void (*Callback)(QQmlNotifierEndpoint *, void **);
12
17
19 nullptr,
24};
25
26namespace {
27 struct NotifyListTraversalData {
28 NotifyListTraversalData(QQmlNotifierEndpoint *ep = nullptr)
29 : originalSenderPtr(0)
30 , disconnectWatch(nullptr)
31 , endpoint(ep)
32 {}
33
34 qintptr originalSenderPtr;
35 qintptr *disconnectWatch;
36 QQmlNotifierEndpoint *endpoint;
37 };
38}
39
40void QQmlNotifier::notify(QQmlData *ddata, int notifierIndex)
41{
42 if (QQmlNotifierEndpoint *ep = ddata->notify(notifierIndex))
43 emitNotify(ep, nullptr);
44}
45
46void QQmlNotifier::emitNotify(QQmlNotifierEndpoint *endpoint, void **a)
47{
49 while (endpoint) {
50 stack.append(NotifyListTraversalData(endpoint));
51 endpoint = endpoint->next;
52 }
53
54 int i = 0;
55 for (; i < stack.size(); ++i) {
56 NotifyListTraversalData &data = stack[i];
57
58 if (!data.endpoint->isNotifying()) {
59 data.endpoint->startNotifying(&data.originalSenderPtr);
60 data.disconnectWatch = &data.originalSenderPtr;
61 } else {
62 data.disconnectWatch = (qintptr *)(data.endpoint->senderPtr & ~0x1);
63 }
64 }
65
66 while (--i >= 0) {
67 NotifyListTraversalData &data = stack[i];
68 if (*data.disconnectWatch) {
69 Q_ASSERT(QQmlNotifier_callbacks[data.endpoint->callback]);
70 QQmlNotifier_callbacks[data.endpoint->callback](data.endpoint, a);
71 if (data.disconnectWatch == &data.originalSenderPtr && data.originalSenderPtr) {
72 data.endpoint->stopNotifying(&data.originalSenderPtr);
73 }
74 }
75 }
76}
77
83{
84 disconnect();
85
87 if (QObjectPrivate::get(source)->threadData.loadRelaxed()->threadId.loadRelaxed() !=
88 QObjectPrivate::get(engine)->threadData.loadRelaxed()->threadId.loadRelaxed()) {
89
90 QString sourceName;
91 QDebug(&sourceName) << source;
92 sourceName = sourceName.left(sourceName.size() - 1);
93 QString engineName;
94 QDebug(&engineName).nospace() << engine;
95 engineName = engineName.left(engineName.size() - 1);
96
97 qFatal("QQmlEngine: Illegal attempt to connect to %s that is in"
98 " a different thread than the QML engine %s.", qPrintable(sourceName),
99 qPrintable(engineName));
100 }
101
103 this->sourceSignal = sourceSignal;
105 QQmlData *ddata = QQmlData::get(source, true);
106 ddata->addNotify(sourceSignal, this);
107 if (doNotify) {
108 needsConnectNotify = doNotify;
110 priv->connectNotify(QMetaObjectPrivate::signal(source->metaObject(), sourceSignal));
111 }
112}
113
115
Type loadRelaxed() const noexcept
\inmodule QtCore
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:153
QAtomicPointer< QThreadData > threadData
Definition qobject_p.h:202
\inmodule QtCore
Definition qobject.h:90
QQmlNotifierEndpoint * notify(int index)
Definition qqmldata_p.h:321
void addNotify(int index, QQmlNotifierEndpoint *)
static QQmlData * get(QObjectPrivate *priv, bool create)
Definition qqmldata_p.h:199
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
void setSender(qintptr sender)
void connect(QObject *source, int sourceSignal, QQmlEngine *engine, bool doNotify=true)
static void flushSignal(const QObject *sender, int signal_index)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
qsizetype size() const
Returns the number of characters in this string.
Definition qstring.h:182
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
Definition qstring.cpp:5161
constexpr size_type size() const noexcept
void append(const T &t)
Combined button and popup list for selecting options.
static bool doNotify(QObject *, QEvent *)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
#define qFatal
Definition qlogging.h:164
static const QMetaObjectPrivate * priv(const uint *data)
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei GLsizei GLchar * source
void QQmlVMEMetaObjectEndpoint_callback(QQmlNotifierEndpoint *, void **)
void QQmlJavaScriptExpressionGuard_callback(QQmlNotifierEndpoint *, void **)
static Callback QQmlNotifier_callbacks[]
void QQmlBoundSignal_callback(QQmlNotifierEndpoint *, void **)
QT_BEGIN_NAMESPACE typedef void(* Callback)(QQmlNotifierEndpoint *, void **)
void QQmlPropertyGuard_callback(QQmlNotifierEndpoint *, void **)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define qPrintable(string)
Definition qstring.h:1391
ptrdiff_t qintptr
Definition qtypes.h:71
QObject::connect nullptr
QJSEngine engine
[0]
static Q_CORE_EXPORT QMetaMethod signal(const QMetaObject *m, int signal_index)