4#include <QtQml/private/qjsvalue_p.h>
5#include <QtQml/private/qqmlglobal_p.h>
6#include <QtQml/private/qqmlmetatype_p.h>
7#include <QtQml/private/qv4qobjectwrapper_p.h>
8#include <QtQml/private/qv4alloca_p.h>
9#include <QtQml/qqmlengine.h>
11#include <QtCore/private/qvariant_p.h>
12#include <QtCore/qcoreapplication.h>
13#include <QtCore/qdebug.h>
14#include <QtCore/qstringlist.h>
19 const QString &propertyType,
const QString &propertyName) {
20 auto stackTrace = engine->stackTrace(1);
21 QString errorLocation;
22 if (!stackTrace.isEmpty()) {
23 const auto& stackTop = stackTrace[0];
24 errorLocation = QString::fromLatin1(
"%1:%2: ").arg(stackTop.source, QString::number(stackTop.line));
27 << QLatin1String(
"%4Could not convert %1 to %2 for property %3")
28 .arg(propertyValue, propertyType, propertyName, errorLocation);
34 switch (metaType.id()) {
37 case QMetaType::Nullptr:
38 case QMetaType::QVariant:
41 case QMetaType::LongLong:
42 case QMetaType::ULongLong:
43 case QMetaType::Float:
44 case QMetaType::Double:
46 case QMetaType::ULong:
47 case QMetaType::Short:
48 case QMetaType::UShort:
50 case QMetaType::SChar:
51 case QMetaType::UChar:
52 case QMetaType::QChar:
53 case QMetaType::QString:
55 case QMetaType::QDateTime:
56 case QMetaType::QDate:
57 case QMetaType::QTime:
59 case QMetaType::QRegularExpression:
60 case QMetaType::QByteArray:
61 case QMetaType::QLocale:
68 if (metaType == QMetaType::fromType<QJSValue>())
72 if (metaType.flags() &
73 (QMetaType::PointerToQObject
74 | QMetaType::IsEnumeration
75 | QMetaType::SharedPointerToQObject
76 | QMetaType::WeakPointerToQObject
77 | QMetaType::TrackingPointerToQObject
78 | QMetaType::IsUnsignedEnumeration
79 | QMetaType::PointerToGadget
80 | QMetaType::IsPointer
81 | QMetaType::IsQmlList)) {
88template<
typename JSValue>
91 if constexpr (std::is_same_v<JSValue, QJSValue>)
92 return QJSValue::NullValue;
93 if constexpr (std::is_same_v<JSValue, QJSPrimitiveValue>)
94 return QJSPrimitiveNull();
97template<
typename JSValue>
100 if (!fromType.isValid()) {
105 if ((fromType.flags() & QMetaType::PointerToQObject)
106 && *
static_cast<QObject *
const *>(from) ==
nullptr) {
107 *to = nullValue<JSValue>();
111 switch (fromType.id()) {
112 case QMetaType::Void:
115 case QMetaType::Bool:
116 *to = JSValue(*
static_cast<
const bool *>(from));
119 *to = JSValue(*
static_cast<
const int *>(from));
121 case QMetaType::Double:
122 *to = JSValue(*
static_cast<
const double *>(from));
124 case QMetaType::QString:
125 *to = JSValue(*
static_cast<
const QString *>(from));
127 case QMetaType::Nullptr:
128 *to = nullValue<JSValue>();
136 QMetaType fromType,
const void *from, QMetaType toType,
void *to,
137 QV4::ExecutionEngine *engine)
144 if (QMetaType::convert(fromType, from, toType, to))
147 if (toType == QMetaType::fromType<QJSPrimitiveValue>())
148 return coerceToJSValue(fromType, from,
static_cast<QJSPrimitiveValue *>(to));
150 if (toType == QMetaType::fromType<QJSValue>()) {
151 if (coerceToJSValue(fromType, from,
static_cast<QJSValue *>(to)))
157 QV4::Scope scope(engine);
158 QV4::ScopedValue v(scope, scope.engine->metaTypeToJS(fromType, from));
159 *
static_cast<QJSValue *>(to) = QJSValuePrivate::fromReturnedValue(v->asReturnedValue());
163 if (toType == QMetaType::fromType<QJSManagedValue>()) {
167 QV4::Scope scope(engine);
168 QV4::ScopedValue v(scope, scope.engine->metaTypeToJS(fromType, from));
169 *
static_cast<QJSManagedValue *>(to) = QJSManagedValue(
170 QJSValuePrivate::fromReturnedValue(v->asReturnedValue()), engine->jsEngine());
180 const QtPrivate::QMetaTypeInterface *iface = type.iface();
181 QVariant::Private *d = &variant->data_ptr();
182 Q_ASSERT(d->is_null && !d->is_shared);
183 *d = QVariant::Private(iface);
184 if (QVariant::Private::canUseInternalSpace(iface))
189 d->data.shared = QVariant::PrivateShared::create(iface->size, iface->alignment);
191 return d->data.shared->data();
195 const QMetaObject *targetMetaObject,
int i,
void **args,
int argc,
void *target)
197 Q_ALLOCA_VAR(
void *, p, (argc + 1) *
sizeof(
void *));
199 memcpy(p + 1, args, argc *
sizeof(
void *));
200 targetMetaObject->static_metacall(QMetaObject::ConstructInPlace, i, p);
204 const QMetaObject *targetMetaObject,
int i,
void *source,
void *target)
206 void *p[] = { target, source };
207 targetMetaObject->static_metacall(QMetaObject::ConstructInPlace, i, p);
211template<
typename Allocate>
213 const QMetaObject *targetMetaObject,
int ctorIndex,
void **args,
216 const QMetaMethod ctor = targetMetaObject->constructor(ctorIndex);
217 callConstructor(targetMetaObject, ctorIndex, args, ctor.parameterCount(), allocate());
221template<
typename Allocate,
typename Retrieve>
223 const QMetaObject *targetMetaObject, Allocate &&allocate, Retrieve &&retrieve,
224 QV4::ExecutionEngine *engine)
226 const int end = targetMetaObject->constructorCount();
227 for (
int i = 0; i < end; ++i) {
229 const QMetaMethod ctor = targetMetaObject->constructor(i);
230 if (ctor.parameterCount() != 1)
233 if (retrieve([&](QMetaType sourceMetaType,
void *sourceData) {
234 if (sourceMetaType != ctor.parameterMetaType(0))
236 callConstructor(targetMetaObject, i, sourceData, allocate());
243 for (
int i = 0; i < end; ++i) {
245 const QMetaMethod ctor = targetMetaObject->constructor(i);
246 if (ctor.parameterCount() != 1)
249 const QMetaType parameterType = ctor.parameterMetaType(0);
250 const QMetaObject *parameterMetaObject = parameterType.metaObject();
251 if (!parameterMetaObject)
254 if (retrieve([&](QMetaType sourceMetaType,
void *sourceData) {
255 Q_ASSERT(sourceMetaType != parameterType);
256 if (
const QMetaObject *sourceMetaObject = sourceMetaType.metaObject();
257 sourceMetaObject && sourceMetaObject->inherits(parameterMetaObject)) {
258 callConstructor(targetMetaObject, i, sourceData, allocate());
267 for (
int i = 0; i < end; ++i) {
271 const QMetaMethod ctor = targetMetaObject->constructor(i);
272 if (ctor.parameterCount() != 1)
275 const QMetaType parameterType = ctor.parameterMetaType(0);
277 if (retrieve([&](QMetaType sourceMetaType,
void *sourceData) {
278 QVariant converted(parameterType);
279 if (coerceValue(sourceMetaType, sourceData, parameterType, converted.data(), engine)) {
280 callConstructor(targetMetaObject, i, converted.data(), allocate());
293template<
typename Allocate>
295 const QMetaObject *targetMetaObject,
const QV4::Value &source, Allocate &&allocate,
296 QV4::ExecutionEngine *engine)
299 return fromMatchingType(targetMetaObject, std::forward<Allocate>(allocate), [&](
auto callback) {
300 if (!variant.isValid())
301 variant = QV4::ExecutionEngine::toVariant(source, QMetaType());
302 return callback(variant.metaType(), variant.data());
306template<
typename Allocate>
308 const QMetaObject *targetMetaObject, QVariant source, Allocate &&allocate,
309 QV4::ExecutionEngine *engine)
311 return fromMatchingType(targetMetaObject, std::forward<Allocate>(allocate), [&](
auto callback) {
312 return callback(source.metaType(), source.data());
316template<
typename Allocate>
317static bool fromString(
const QMetaObject *mo, QString s, Allocate &&allocate)
319 for (
int i = 0, end = mo->constructorCount(); i < end; ++i) {
320 const QMetaMethod ctor = mo->constructor(i);
321 if (ctor.parameterCount() != 1)
324 if (ctor.parameterMetaType(0) == QMetaType::fromType<QString>()) {
325 callConstructor(mo, i, &s, allocate());
333template<
typename Get,
typename Convert>
335 const QMetaProperty &metaProperty,
void *target, Get &&get, Convert &&convert,
336 QV4::ExecutionEngine *engine)
338 const QMetaType propertyType = metaProperty.metaType();
339 QVariant property = get(propertyType);
340 if (property.metaType() == propertyType) {
341 metaProperty.writeOnGadget(target, std::move(property));
345 QVariant converted = convert(propertyType);
346 if (converted.isValid()) {
347 metaProperty.writeOnGadget(target, std::move(converted));
351 converted = QVariant(propertyType);
353 property.metaType(), property.constData(), propertyType, converted.data(),
355 metaProperty.writeOnGadget(target, std::move(converted));
363 const QMetaObject *targetMetaObject,
void *target,
const QV4::Value &source,
364 QV4::ExecutionEngine *engine)
366 const QV4::Object *o =
static_cast<
const QV4::Object *>(&source);
367 QV4::Scope scope(o->engine());
368 QV4::ScopedObject object(scope, o);
370 for (
int i = 0; i < targetMetaObject->propertyCount(); ++i) {
371 const QMetaProperty metaProperty = targetMetaObject->property(i);
372 const QString propertyName = QString::fromUtf8(metaProperty.name());
374 QV4::ScopedString v4PropName(scope, scope.engine->newString(propertyName));
375 QV4::ScopedValue v4PropValue(scope, object->get(v4PropName));
379 if (v4PropValue->isUndefined())
382 if (doWriteProperty(metaProperty, target, [&](
const QMetaType &propertyType) {
383 return QV4::ExecutionEngine::toVariant(v4PropValue, propertyType);
384 }, [&](
const QMetaType &propertyType) {
385 return QQmlValueTypeProvider::createValueType(v4PropValue, propertyType, engine);
390 const QMetaType propertyType = metaProperty.metaType();
391 QVariant property = QV4::ExecutionEngine::toVariant(v4PropValue, propertyType);
392 if (property.metaType() == propertyType) {
393 metaProperty.writeOnGadget(target, std::move(property));
397 QVariant converted = QQmlValueTypeProvider::createValueType(
398 v4PropValue, propertyType, engine);
399 if (converted.isValid()) {
400 metaProperty.writeOnGadget(target, std::move(converted));
404 converted = QVariant(propertyType);
406 property.metaType(), property.constData(), propertyType, converted.data(),
408 metaProperty.writeOnGadget(target, std::move(converted));
412 printConversionWarning(engine, v4PropValue->toQStringNoThrow(),
413 QString::fromUtf8(propertyType.name()), propertyName);
418 const QMetaObject *targetMetaObject, QMetaType metaType,
const QV4::Value &source,
419 QV4::ExecutionEngine *engine)
421 if (!source.isObject() || !targetMetaObject)
424 QVariant result(metaType);
425 doWriteProperties(targetMetaObject, result.data(), source, engine);
429template<
typename Read>
431 const QMetaObject *targetMetaObject,
void *target,
432 const QMetaObject *sourceMetaObject, Read &&read, QV4::ExecutionEngine *engine)
434 for (
int i = 0; i < targetMetaObject->propertyCount(); ++i) {
435 const QMetaProperty metaProperty = targetMetaObject->property(i);
437 const int sourceProperty = sourceMetaObject->indexOfProperty(metaProperty.name());
441 if (sourceProperty == -1)
444 const QMetaType propertyType = metaProperty.metaType();
445 QVariant property = read(sourceMetaObject, sourceProperty);
446 if (property.metaType() == propertyType) {
447 metaProperty.writeOnGadget(target, std::move(property));
451 QVariant converted = QQmlValueTypeProvider::createValueType(property, propertyType, engine);
452 if (converted.isValid()) {
453 metaProperty.writeOnGadget(target, std::move(converted));
457 converted = QVariant(propertyType);
459 property.metaType(), property.constData(), propertyType, converted.data(),
461 metaProperty.writeOnGadget(target, std::move(converted));
465 printConversionWarning(engine, QDebug::toString(property),
466 QString::fromUtf8(propertyType.name()),
467 QString::fromUtf8(metaProperty.name()));
473 const QMetaObject *targetMeta,
void *target, QObject *source, QV4::ExecutionEngine *engine)
476 targetMeta, target, source->metaObject(),
477 [source](
const QMetaObject *sourceMetaObject,
int sourceProperty) {
478 return sourceMetaObject->property(sourceProperty).read(source);
483 const QMetaObject *targetMetaObject, QMetaType targetMetaType, QObject *source,
484 QV4::ExecutionEngine *engine)
486 if (!source || !targetMetaObject)
489 QVariant result(targetMetaType);
490 doWriteProperties(targetMetaObject, result.data(), source, engine);
495 const QMetaObject *targetMetaObject, QMetaType targetMetaType,
496 const QMetaObject *sourceMetaObject,
const void *source, QV4::ExecutionEngine *engine)
498 if (!source || !sourceMetaObject || !targetMetaObject)
501 QVariant result(targetMetaType);
503 targetMetaObject, result.data(), sourceMetaObject,
504 [source](
const QMetaObject *sourceMetaObject,
int sourceProperty) {
505 return sourceMetaObject->property(sourceProperty).readOnGadget(source);
510template<
typename Map>
512 const QMetaObject *targetMetaObject,
void *target,
const Map &source,
513 QV4::ExecutionEngine *engine)
515 for (
int i = 0; i < targetMetaObject->propertyCount(); ++i) {
516 const QMetaProperty metaProperty = targetMetaObject->property(i);
520 const auto it = source.constFind(QString::fromUtf8(metaProperty.name()));
521 if (it == source.constEnd())
524 const QMetaType propertyType = metaProperty.metaType();
525 QVariant property = *it;
526 if (property.metaType() == propertyType) {
527 metaProperty.writeOnGadget(target, std::move(property));
531 QVariant converted = QQmlValueTypeProvider::createValueType(property, propertyType, engine);
532 if (converted.isValid()) {
533 metaProperty.writeOnGadget(target, std::move(converted));
537 converted = QVariant(propertyType);
539 property.metaType(), property.constData(), propertyType, converted.data(),
541 metaProperty.writeOnGadget(target, std::move(converted));
545 printConversionWarning(engine, QDebug::toString(property),
546 QString::fromUtf8(propertyType.name()),
547 QString::fromUtf8(metaProperty.name()));
551template<
typename Map>
553 const QMetaObject *targetMetaObject, QMetaType targetMetaType,
const Map &source,
554 QV4::ExecutionEngine *engine)
556 QVariant result(targetMetaType);
557 doWriteProperties(targetMetaObject, result.data(), source, engine);
562 const QMetaObject *targetMetaObject, QMetaType targetMetaType,
const QVariant &source,
563 QV4::ExecutionEngine *engine)
565 if (!targetMetaObject)
568 if (source.metaType() == QMetaType::fromType<QJSValue>()) {
569 QJSValue val = source.value<QJSValue>();
575 targetMetaObject, targetMetaType,
576 QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(&val)),
580 if (source.metaType() == QMetaType::fromType<QVariantMap>()) {
582 targetMetaObject, targetMetaType,
583 *
static_cast<
const QVariantMap *>(source.constData()), engine);
586 if (source.metaType() == QMetaType::fromType<QVariantHash>()) {
588 targetMetaObject, targetMetaType,
589 *
static_cast<
const QVariantHash *>(source.constData()), engine);
592 if (source.metaType().flags() & QMetaType::PointerToQObject)
593 return byProperties(targetMetaObject, targetMetaType, source.value<QObject *>(), engine);
595 if (
const QMetaObject *sourceMeta = QQmlMetaType::metaObjectForValueType(source.metaType())) {
597 targetMetaObject, targetMetaType, sourceMeta, source.constData(), engine);
603template<
typename Allocate,
typename DefaultConstruct>
605 const QQmlType &targetType,
const QV4::Value &source,
606 Allocate &&allocate, DefaultConstruct &&defaultConstruct, QV4::ExecutionEngine *engine)
608 const auto warn = [&](
const QMetaObject *targetMetaObject) {
610 <<
"Could not find any constructor for value type"
611 << targetMetaObject->className() <<
"to call with value"
612 << source.toQStringNoThrow();
615 if (targetType.canPopulateValueType()) {
616 if (
const QMetaObject *targetMetaObject = targetType.metaObjectForValueType()) {
617 if (source.isObject()) {
618 doWriteProperties(targetMetaObject, defaultConstruct(), source, engine);
621 if (targetType.canConstructValueType()) {
622 if (fromMatchingType(targetMetaObject, source, allocate, engine))
624 warn(targetMetaObject);
627 }
else if (targetType.canConstructValueType()) {
628 if (
const QMetaObject *targetMetaObject = targetType.metaObjectForValueType()) {
629 if (fromMatchingType(targetMetaObject, source, allocate, engine))
631 warn(targetMetaObject);
635 if (
const auto valueTypeFunction = targetType.createValueTypeFunction()) {
636 const QVariant result
637 = valueTypeFunction(QJSValuePrivate::fromReturnedValue(source.asReturnedValue()));
638 const QMetaType resultType = result.metaType();
639 if (resultType == targetType.typeId()) {
640 resultType.construct(allocate(), result.constData());
648template<
typename Allocate,
typename DefaultConstruct>
650 const QQmlType &targetType, QMetaType sourceMetaType,
void *source,
651 Allocate &&allocate, DefaultConstruct &&defaultConstruct, QV4::ExecutionEngine *engine)
654 const auto warn = [&](
const QMetaObject *targetMetaObject) {
656 <<
"Could not find any constructor for value type"
657 << targetMetaObject->className() <<
"to call with value" << source;
660 if (targetType.canPopulateValueType()) {
661 if (
const QMetaObject *targetMetaObject = targetType.metaObjectForValueType()) {
662 if (
const QMetaObject *sourceMetaObject
663 = QQmlMetaType::metaObjectForValueType(sourceMetaType)) {
665 targetMetaObject, defaultConstruct(), sourceMetaObject,
666 [&source](
const QMetaObject *sourceMetaObject,
int sourceProperty) {
667 return sourceMetaObject->property(sourceProperty).readOnGadget(source);
672 if (sourceMetaType == QMetaType::fromType<QVariantMap>()) {
674 targetMetaObject, defaultConstruct(),
675 *
static_cast<
const QVariantMap *>(source), engine);
679 if (sourceMetaType == QMetaType::fromType<QVariantHash>()) {
681 targetMetaObject, defaultConstruct(),
682 *
static_cast<
const QVariantHash *>(source), engine);
686 if (sourceMetaType.flags() & QMetaType::PointerToQObject) {
688 targetMetaObject, defaultConstruct(),
689 *
static_cast<QObject *
const *>(source), engine);
695 if (targetType.canConstructValueType()) {
696 if (
const QMetaObject *targetMetaObject = targetType.metaObjectForValueType()) {
697 if (fromMatchingType(
698 targetMetaObject, std::forward<Allocate>(allocate), [&](
auto callback) {
699 return callback(sourceMetaType, source);
703 warn(targetMetaObject);
711
712
713
714
715
716
717
718bool QQmlValueTypeProvider::populateValueType(
719 QMetaType targetMetaType,
void *target, QMetaType sourceMetaType,
void *source,
720 QV4::ExecutionEngine *engine)
722 if (sourceMetaType == QMetaType::fromType<QJSValue>()) {
723 const QJSValue *val =
static_cast<
const QJSValue *>(source);
728 return populateValueType(
729 targetMetaType, target,
730 QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(val)),
734 if (!isConstructibleMetaType(targetMetaType))
737 return createOrConstructValueType(
738 QQmlMetaType::qmlType(targetMetaType), sourceMetaType, source,
739 [targetMetaType, target]() {
740 targetMetaType.destruct(target);
748
749
750
751
752
753
754
755bool QQmlValueTypeProvider::populateValueType(
756 QMetaType targetMetaType,
void *target,
const QV4::Value &source,
757 QV4::ExecutionEngine *engine)
759 if (!isConstructibleMetaType(targetMetaType))
762 return createOrConstructValueType(
763 QQmlMetaType::qmlType(targetMetaType), source, [targetMetaType, target]() {
764 targetMetaType.destruct(target);
772
773
774
775void *QQmlValueTypeProvider::heapCreateValueType(
776 const QQmlType &targetType,
const QV4::Value &source, QV4::ExecutionEngine *engine)
778 void *target =
nullptr;
779 if (createOrConstructValueType(
780 targetType, source, [&]() {
781 const QMetaType metaType = targetType.typeId();
782 const ushort align = metaType.alignOf();
783 target = align > __STDCPP_DEFAULT_NEW_ALIGNMENT__
784 ? operator
new(metaType.sizeOf(), std::align_val_t(align))
785 : operator
new(metaType.sizeOf());
788 target = targetType.typeId().create();
791 Q_ASSERT(target !=
nullptr);
797QVariant QQmlValueTypeProvider::constructValueType(
798 QMetaType targetMetaType,
const QMetaObject *targetMetaObject,
799 int ctorIndex,
void **args)
802 fromVerifiedType(targetMetaObject, ctorIndex, args,
803 [&]() {
return createVariantData(targetMetaType, &result); });
809 if (
const auto valueTypeFunction = type.createValueTypeFunction()) {
810 const QVariant result = valueTypeFunction(s);
811 if (result.metaType() == metaType)
818QVariant QQmlValueTypeProvider::createValueType(
const QJSValue &s, QMetaType metaType)
820 if (!isConstructibleMetaType(metaType))
822 return fromJSValue(QQmlMetaType::qmlType(metaType), s, metaType);
825QVariant QQmlValueTypeProvider::createValueType(
const QString &s, QMetaType metaType)
827 if (!isConstructibleMetaType(metaType))
829 const QQmlType type = QQmlMetaType::qmlType(metaType);
830 if (type.canConstructValueType()) {
831 if (
const QMetaObject *mo = type.metaObjectForValueType()) {
833 if (fromString(mo, s, [&]() {
return createVariantData(metaType, &result); }))
838 return fromJSValue(type, s, metaType);
841QVariant QQmlValueTypeProvider::createValueType(
842 const QV4::Value &s, QMetaType metaType, QV4::ExecutionEngine *engine)
844 if (!isConstructibleMetaType(metaType))
846 const QQmlType type = QQmlMetaType::qmlType(metaType);
847 const auto warn = [&](
const QMetaObject *mo) {
849 <<
"Could not find any constructor for value type"
850 << mo->className() <<
"to call with value" << s.toQStringNoThrow();
853 if (type.canPopulateValueType()) {
854 if (
const QMetaObject *mo = type.metaObject()) {
855 QVariant result = byProperties(mo, metaType, s, engine);
856 if (result.isValid())
858 if (type.canConstructValueType()) {
859 if (fromMatchingType(
860 mo, s, [&]() {
return createVariantData(metaType, &result); },
867 }
else if (type.canConstructValueType()) {
868 if (
const QMetaObject *mo = type.metaObject()) {
870 if (fromMatchingType(
871 mo, s, [&]() {
return createVariantData(metaType, &result); },
879 return fromJSValue(type, QJSValuePrivate::fromReturnedValue(s.asReturnedValue()), metaType);
884
885
886
887QVariant QQmlValueTypeProvider::createValueType(
888 const QVariant &s, QMetaType metaType, QV4::ExecutionEngine *engine)
890 if (!isConstructibleMetaType(metaType))
892 const QQmlType type = QQmlMetaType::qmlType(metaType);
893 const auto warn = [&](
const QMetaObject *mo) {
895 <<
"Could not find any constructor for value type"
896 << mo->className() <<
"to call with value" << s;
899 if (type.canPopulateValueType()) {
900 if (
const QMetaObject *mo = type.metaObjectForValueType()) {
901 QVariant result = byProperties(mo, metaType, s, engine);
902 if (result.isValid())
904 if (type.canConstructValueType()) {
905 if (fromMatchingType(
906 mo, s, [&]() {
return createVariantData(metaType, &result); },
913 }
else if (type.canConstructValueType()) {
914 if (
const QMetaObject *mo = type.metaObjectForValueType()) {
916 if (fromMatchingType(
917 mo, s, [&]() {
return createVariantData(metaType, &result); },
928QQmlColorProvider::~QQmlColorProvider() {}
929QVariant QQmlColorProvider::colorFromString(
const QString &,
bool *ok) {
if (ok) *ok =
false;
return QVariant(); }
930unsigned QQmlColorProvider::rgbaFromString(
const QString &,
bool *ok) {
if (ok) *ok =
false;
return 0; }
931QVariant QQmlColorProvider::fromRgbF(
double,
double,
double,
double) {
return QVariant(); }
932QVariant QQmlColorProvider::fromHslF(
double,
double,
double,
double) {
return QVariant(); }
933QVariant QQmlColorProvider::fromHsvF(
double,
double,
double,
double) {
return QVariant(); }
934QVariant QQmlColorProvider::lighter(
const QVariant &, qreal) {
return QVariant(); }
935QVariant QQmlColorProvider::darker(
const QVariant &, qreal) {
return QVariant(); }
936QVariant QQmlColorProvider::alpha(
const QVariant &, qreal)
940QVariant QQmlColorProvider::tint(
const QVariant &,
const QVariant &) {
return QVariant(); }
946 QQmlColorProvider *old = colorProvider;
947 colorProvider = newProvider;
954 qWarning() <<
"Warning: QQml_colorProvider: no color provider has been set!";
955 static QQmlColorProvider nullColorProvider;
959 return &colorProvider;
964 static QQmlColorProvider **providerPtr = getColorProvider();
969QQmlGuiProvider::~QQmlGuiProvider() {}
970QQmlApplication *QQmlGuiProvider::application(QObject *parent)
972 return new QQmlApplication(parent);
974QStringList QQmlGuiProvider::fontFamilies() {
return QStringList(); }
975bool QQmlGuiProvider::openUrlExternally(
const QUrl &) {
return false; }
977QObject *QQmlGuiProvider::inputMethod()
980 QObject *o =
new QObject();
981 o->setObjectName(QStringLiteral(
"No inputMethod available"));
982 QQmlEngine::setObjectOwnership(o, QQmlEngine::JavaScriptOwnership);
986QObject *QQmlGuiProvider::styleHints()
988 QObject *o =
new QObject();
989 o->setObjectName(QStringLiteral(
"No styleHints available"));
990 QQmlEngine::setObjectOwnership(o, QQmlEngine::JavaScriptOwnership);
994QString QQmlGuiProvider::pluginName()
const {
return QString(); }
1000 QQmlGuiProvider *old = guiProvider;
1001 guiProvider = newProvider;
1008 static QQmlGuiProvider nullGuiProvider;
1012 return &guiProvider;
1017 static QQmlGuiProvider **providerPtr = getGuiProvider();
1018 return *providerPtr;
1022QQmlApplication::QQmlApplication(QObject *parent)
1023 : QQmlApplication(*(
new QQmlApplicationPrivate), parent)
1027QQmlApplication::QQmlApplication(QQmlApplicationPrivate &dd, QObject *parent)
1028 : QObject(dd, parent)
1030 connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
1031 this, SIGNAL(aboutToQuit()));
1032 connect(QCoreApplication::instance(), SIGNAL(applicationNameChanged()),
1033 this, SIGNAL(nameChanged()));
1034 connect(QCoreApplication::instance(), SIGNAL(applicationVersionChanged()),
1035 this, SIGNAL(versionChanged()));
1036 connect(QCoreApplication::instance(), SIGNAL(organizationNameChanged()),
1037 this, SIGNAL(organizationChanged()));
1038 connect(QCoreApplication::instance(), SIGNAL(organizationDomainChanged()),
1039 this, SIGNAL(domainChanged()));
1042QStringList QQmlApplication::args()
1044 Q_D(QQmlApplication);
1047 d->args = QCoreApplication::arguments();
1052QString QQmlApplication::name()
const
1054 return QCoreApplication::instance()->applicationName();
1057QString QQmlApplication::version()
const
1059 return QCoreApplication::instance()->applicationVersion();
1062QString QQmlApplication::organization()
const
1064 return QCoreApplication::instance()->organizationName();
1067QString QQmlApplication::domain()
const
1069 return QCoreApplication::instance()->organizationDomain();
1072void QQmlApplication::setName(
const QString &arg)
1074 QCoreApplication::instance()->setApplicationName(arg);
1077void QQmlApplication::setVersion(
const QString &arg)
1079 QCoreApplication::instance()->setApplicationVersion(arg);
1082void QQmlApplication::setOrganization(
const QString &arg)
1084 QCoreApplication::instance()->setOrganizationName(arg);
1087void QQmlApplication::setDomain(
const QString &arg)
1089 QCoreApplication::instance()->setOrganizationDomain(arg);
1095 auto ddata = QQmlData::get(object,
false);
1096 return (ddata && ddata->propertyCache) ? ddata :
nullptr;
1102 if (
const QQmlData *ddata = ddata_for_cast(object))
1103 return ddata->propertyCache->firstCppMetaObject()->inherits(mo);
1104 return object->metaObject()->inherits(mo);
1109 Q_ASSERT(type.isValid());
1112 const QMetaObject *typeMetaObject = type.metaObject();
1113 const QQmlPropertyCache::ConstPtr typePropertyCache = typeMetaObject
1114 ? QQmlPropertyCache::ConstPtr()
1115 : QQmlMetaType::findPropertyCacheInCompositeTypes(type.typeId());
1117 if (
const QQmlData *ddata = ddata_for_cast(object)) {
1118 for (
const QQmlPropertyCache *propertyCache = ddata->propertyCache.data(); propertyCache;
1119 propertyCache = propertyCache->parent().data()) {
1121 if (typeMetaObject) {
1128 if (
const QMetaObject *objectMetaObject = propertyCache->metaObject())
1129 return objectMetaObject->inherits(typeMetaObject);
1135 if (propertyCache == typePropertyCache.data())
1143 return object->metaObject()->inherits(typeMetaObject
1145 : (typePropertyCache ? typePropertyCache->createMetaObject() :
nullptr));
1150#include "moc_qqmlglobal_p.cpp"
static void doWriteProperties(const QMetaObject *targetMetaObject, void *target, const QV4::Value &source, QV4::ExecutionEngine *engine)
static QQmlGuiProvider ** getGuiProvider(void)
static bool fromMatchingType(const QMetaObject *targetMetaObject, QVariant source, Allocate &&allocate, QV4::ExecutionEngine *engine)
static bool fromMatchingType(const QMetaObject *targetMetaObject, const QV4::Value &source, Allocate &&allocate, QV4::ExecutionEngine *engine)
static bool fromMatchingType(const QMetaObject *targetMetaObject, Allocate &&allocate, Retrieve &&retrieve, QV4::ExecutionEngine *engine)
bool coerceToJSValue(QMetaType fromType, const void *from, JSValue *to)
static void callConstructor(const QMetaObject *targetMetaObject, int i, void *source, void *target)
static void callConstructor(const QMetaObject *targetMetaObject, int i, void **args, int argc, void *target)
static void doWriteProperties(const QMetaObject *targetMetaObject, void *target, const QMetaObject *sourceMetaObject, Read &&read, QV4::ExecutionEngine *engine)
bool createOrConstructValueType(const QQmlType &targetType, const QV4::Value &source, Allocate &&allocate, DefaultConstruct &&defaultConstruct, QV4::ExecutionEngine *engine)
static QVariant fromJSValue(const QQmlType &type, const QJSValue &s, QMetaType metaType)
static bool fromString(const QMetaObject *mo, QString s, Allocate &&allocate)
static QVariant byProperties(const QMetaObject *targetMetaObject, QMetaType targetMetaType, const QMetaObject *sourceMetaObject, const void *source, QV4::ExecutionEngine *engine)
static void fromVerifiedType(const QMetaObject *targetMetaObject, int ctorIndex, void **args, Allocate &&allocate)
bool createOrConstructValueType(const QQmlType &targetType, QMetaType sourceMetaType, void *source, Allocate &&allocate, DefaultConstruct &&defaultConstruct, QV4::ExecutionEngine *engine)
static QVariant byProperties(const QMetaObject *targetMetaObject, QMetaType metaType, const QV4::Value &source, QV4::ExecutionEngine *engine)
void doWriteProperties(const QMetaObject *targetMetaObject, void *target, const Map &source, QV4::ExecutionEngine *engine)
static QQmlColorProvider ** getColorProvider(void)
static bool coerceValue(QMetaType fromType, const void *from, QMetaType toType, void *to, QV4::ExecutionEngine *engine)
static void doWriteProperties(const QMetaObject *targetMeta, void *target, QObject *source, QV4::ExecutionEngine *engine)
QVariant byProperties(const QMetaObject *targetMetaObject, QMetaType targetMetaType, const Map &source, QV4::ExecutionEngine *engine)
static QQmlGuiProvider * guiProvider
static bool doWriteProperty(const QMetaProperty &metaProperty, void *target, Get &&get, Convert &&convert, QV4::ExecutionEngine *engine)
static QVariant byProperties(const QMetaObject *targetMetaObject, QMetaType targetMetaType, QObject *source, QV4::ExecutionEngine *engine)
static const QQmlData * ddata_for_cast(QObject *object)
bool qmlobject_can_qml_cast(QObject *object, const QQmlType &type)
static bool isConstructibleMetaType(const QMetaType metaType)
static QT_BEGIN_NAMESPACE void printConversionWarning(QV4::ExecutionEngine *engine, const QString &propertyValue, const QString &propertyType, const QString &propertyName)
static QQmlColorProvider * colorProvider
static void * createVariantData(QMetaType type, QVariant *variant)
Q_QML_EXPORT bool qmlobject_can_cpp_cast(QObject *object, const QMetaObject *mo)