6#include <private/qqmlboundsignal_p.h>
7#include <private/qqmlcontext_p.h>
8#include <private/qqmlexpression_p.h>
9#include <private/qqmlproperty_p.h>
10#include <private/qqmlsignalnames_p.h>
11#include <private/qqmlvmemetaobject_p.h>
12#include <private/qv4jscall_p.h>
13#include <private/qv4qobjectwrapper_p.h>
15#include <QtQml/qqmlcontext.h>
16#include <QtQml/qqmlinfo.h>
18#include <QtCore/qdebug.h>
19#include <QtCore/qloggingcategory.h>
20#include <QtCore/qstringlist.h>
22#include <private/qobject_p.h>
52 , slotIndex(slotIndex)
58 QMetaMethod slot = receiver->metaObject()->method(slotIndex);
62 template<
typename ArgTypeStorage>
95 v4, &typedFunction, metaArgs,
96 self->signalMetaTypes.
data(), self->signalMetaTypes.
size() - 1,
97 [&](
void **argv,
int) {
98 self->receiver->metaObject()->metacall(
99 self->receiver, QMetaObject::InvokeMetaMethod,
100 self->slotIndex, argv);
131 QList<QBiPointer<QQmlBoundSignal, QQmlConnectionSlotDispatcher>>
boundsignals;
140 QList<const QV4::CompiledData::Binding *>
bindings;
217 for (
const auto &bound : std::as_const(
d->boundsignals)) {
222 dispatcher->connection = {};
223 dispatcher->destroyIfLastRef();
240 return d->targetSet ?
d->target.data() :
parent();
256 if (
d->targetSet &&
d->target ==
obj)
259 for (
const auto &bound : std::as_const(
d->boundsignals)) {
263 if (
signal->isNotifying())
273 d->boundsignals.clear();
301 for (
const auto &bound : std::as_const(
d->boundsignals)) {
303 signal->setEnabled(
d->enabled);
305 bound.asT2()->enabled =
enabled;
308 emit enabledChanged();
323 return d->ignoreUnknownSignals;
329 d->ignoreUnknownSignals = ignore;
334 for (
int ii = 0; ii <
props.size(); ++ii) {
339 error(
props.at(ii), QQmlConnections::tr(
"Cannot assign to non-existent property \"%1\"").arg(propName));
348 if (!compilationUnit->stringAt(
target->inheritedTypeNameIndex).isEmpty())
349 error(binding, QQmlConnections::tr(
"Connections: nested objects not allowed"));
351 error(binding, QQmlConnections::tr(
"Connections: syntax error"));
355 error(binding, QQmlConnections::tr(
"Connections: script expected"));
365 p->bindings = bindings;
368void QQmlConnections::connectSignals()
371 if (!
d->componentcomplete || (
d->targetSet && !
target()))
374 if (
d->bindings.isEmpty()) {
375 connectSignalsToMethods();
377 if (lcQmlConnections().isWarningEnabled()) {
378 qmlWarning(
this) <<
tr(
"Implicitly defined onFoo properties in Connections are deprecated. "
379 "Use this syntax instead: function onFoo(<arguments>) { ... }");
381 connectSignalsToBindings();
385void QQmlConnections::connectSignalsToMethods()
396 QQmlRefPointer<QQmlContextData> ctxtdata = ddata->outerContext;
397 for (
int i = ddata->propertyCache->methodOffset(),
398 end = ddata->propertyCache->methodOffset() + ddata->propertyCache->methodCount();
416 signal->setEnabled(
d->enabled);
419 scope, vmeMetaObject->vmeMethod(handler->
coreIndex()));
426 signal->takeExpression(expression);
430 scope.engine,
target, prop.index(),
435 d->boundsignals += slot;
437 }
else if (!
d->ignoreUnknownSignals
439 && propName.
at(2).isUpper()) {
440 qmlWarning(
this) <<
tr(
"Detected function \"%1\" in Connections element. "
441 "This is probably intended to be a signal handler but no "
442 "signal of the target matches the name.").arg(propName);
448void QQmlConnections::connectSignalsToBindings()
453 QQmlRefPointer<QQmlContextData> ctxtdata = ddata ? ddata->outerContext :
nullptr;
457 QString propName =
d->compilationUnit->stringAt(binding->propertyNameIndex);
464 signal->setEnabled(
d->enabled);
466 auto f =
d->compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex];
470 signal->takeExpression(expression);
473 if (!
d->ignoreUnknownSignals)
474 qmlWarning(
this) <<
tr(
"Cannot assign to non-existent property \"%1\"").arg(propName);
482 d->componentcomplete=
false;
488 d->componentcomplete=
true;
494#include "moc_qqmlconnections_p.cpp"
QV4::ExecutionEngine * handle() const
void void Q_DECL_COLD_FUNCTION void warning(const char *msg,...) const Q_ATTRIBUTE_FORMAT_PRINTF(2
Logs a warning message specified with format msg.
static QObjectPrivate * get(QObject *o)
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
QObject * parent() const
Returns a pointer to the parent object.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
void deleteLater()
\threadsafe
QQmlBoundSignalDeleter(QQmlBoundSignal *signal)
~QQmlBoundSignalDeleter()
void applyBindings(QObject *object, const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit, const QList< const QV4::CompiledData::Binding * > &bindings) override
void verifyBindings(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit, const QList< const QV4::CompiledData::Binding * > &props) override
QList< QBiPointer< QQmlBoundSignal, QQmlConnectionSlotDispatcher > > boundsignals
QQmlRefPointer< QV4::ExecutableCompilationUnit > compilationUnit
QList< const QV4::CompiledData::Binding * > bindings
bool ignoreUnknownSignals
QQmlGuard< QObject > target
bool ignoreUnknownSignals
bool isEnabled() const
\qmlproperty bool QtQml::Connections::enabled
void setEnabled(bool enabled)
void setTarget(QObject *)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setIgnoreUnknownSignals(bool ignore)
void classBegin() override
Invoked after class creation, but before any properties have been set.
QQmlConnections(QObject *parent=nullptr)
static QQmlData * get(QObjectPrivate *priv, bool create)
static QQmlEnginePrivate * get(QQmlEngine *e)
The QQmlEngine class provides an environment for instantiating QML components.
The QQmlError class encapsulates a QML error.
QString name(QObject *) const
static QQmlPropertyPrivate * get(const QQmlProperty &p)
The QQmlProperty class abstracts accessing properties on objects created from QML.
static bool isHandlerName(QStringView signalName)
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
qsizetype size() const noexcept
Returns the number of characters in this string.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
QChar * data()
Returns a pointer to the data stored in the QString.
void destroyIfLastRef() noexcept
Combined button and popup list for selecting options.
ReturnedValue coerceAndCall(ExecutionEngine *engine, const Function::JSTypedFunction *typedFunction, const CompiledData::Function *compiledFunction, const Value *argv, int argc, Callable call)
Scoped< ExecutionContext > ScopedContext
DBusConnection const char DBusError * error
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 * method
#define Q_LOGGING_CATEGORY(name,...)
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum GLuint GLsizei const GLenum * props
QQmlEngine * qmlEngine(const QObject *obj)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define qPrintable(string)
TypedFunction(const ArgTypeStorage *storage)
qsizetype parameterCount() const
QMetaType parameterMetaType(qsizetype i) const
QMetaType returnMetaType() const
QQmlMetaObject::ArgTypeStorage< 2 > slotMetaTypes
QQmlConnectionSlotDispatcher(QV4::ExecutionEngine *v4, QObject *sender, int signalIndex, QObject *receiver, int slotIndex, bool enabled)
static void impl(int which, QSlotObjectBase *base, QObject *, void **metaArgs, bool *ret)
QQmlMetaObject::ArgTypeStorage< 2 > signalMetaTypes
QMetaObject::Connection connection
quint32_le propertyNameIndex
union QV4::CompiledData::Binding::@540 value
QQmlError catchExceptionAsQmlError()
QQmlEngine * qmlEngine() const