5#include <QtQml/private/qjsvalue_p.h>
6#include <QtQml/private/qqmlglobal_p.h>
7#include <QtQml/private/qqmlmetatype_p.h>
8#include <QtQml/private/qv4qobjectwrapper_p.h>
9#include <QtQml/private/qv4alloca_p.h>
10#include <QtQml/qqmlengine.h>
12#include <QtCore/private/qvariant_p.h>
13#include <QtCore/qcoreapplication.h>
14#include <QtCore/qdebug.h>
15#include <QtCore/qstringlist.h>
20 const QString &propertyType,
const QString &propertyName) {
21 auto stackTrace = engine->stackTrace(1);
22 QString errorLocation;
23 if (!stackTrace.isEmpty()) {
24 const auto& stackTop = stackTrace[0];
25 errorLocation = QString::fromLatin1(
"%1:%2: ").arg(stackTop.source, QString::number(stackTop.line));
28 << QLatin1String(
"%4Could not convert %1 to %2 for property %3")
29 .arg(propertyValue, propertyType, propertyName, errorLocation);
35 switch (metaType.id()) {
38 case QMetaType::Nullptr:
39 case QMetaType::QVariant:
42 case QMetaType::LongLong:
43 case QMetaType::ULongLong:
44 case QMetaType::Float:
45 case QMetaType::Double:
47 case QMetaType::ULong:
48 case QMetaType::Short:
49 case QMetaType::UShort:
51 case QMetaType::SChar:
52 case QMetaType::UChar:
53 case QMetaType::QChar:
54 case QMetaType::QString:
56 case QMetaType::QDateTime:
57 case QMetaType::QDate:
58 case QMetaType::QTime:
60 case QMetaType::QRegularExpression:
61 case QMetaType::QByteArray:
62 case QMetaType::QLocale:
69 if (metaType == QMetaType::fromType<QJSValue>())
73 if (metaType.flags() &
74 (QMetaType::PointerToQObject
75 | QMetaType::IsEnumeration
76 | QMetaType::SharedPointerToQObject
77 | QMetaType::WeakPointerToQObject
78 | QMetaType::TrackingPointerToQObject
79 | QMetaType::IsUnsignedEnumeration
80 | QMetaType::PointerToGadget
81 | QMetaType::IsPointer
82 | QMetaType::IsQmlList)) {
89template<
typename JSValue>
92 if constexpr (std::is_same_v<JSValue, QJSValue>)
93 return QJSValue::NullValue;
94 if constexpr (std::is_same_v<JSValue, QJSPrimitiveValue>)
95 return QJSPrimitiveNull();
98template<
typename JSValue>
101 if (!fromType.isValid()) {
106 if ((fromType.flags() & QMetaType::PointerToQObject)
107 && *
static_cast<QObject *
const *>(from) ==
nullptr) {
108 *to = nullValue<JSValue>();
112 switch (fromType.id()) {
113 case QMetaType::Void:
116 case QMetaType::Bool:
117 *to = JSValue(*
static_cast<
const bool *>(from));
120 *to = JSValue(*
static_cast<
const int *>(from));
122 case QMetaType::Double:
123 *to = JSValue(*
static_cast<
const double *>(from));
125 case QMetaType::QString:
126 *to = JSValue(*
static_cast<
const QString *>(from));
128 case QMetaType::Nullptr:
129 *to = nullValue<JSValue>();
137 QMetaType fromType,
const void *from, QMetaType toType,
void *to,
138 QV4::ExecutionEngine *engine)
145 if (QMetaType::convert(fromType, from, toType, to))
148 if (toType == QMetaType::fromType<QJSPrimitiveValue>())
149 return coerceToJSValue(fromType, from,
static_cast<QJSPrimitiveValue *>(to));
151 if (toType == QMetaType::fromType<QJSValue>()) {
152 if (coerceToJSValue(fromType, from,
static_cast<QJSValue *>(to)))
158 QV4::Scope scope(engine);
159 QV4::ScopedValue v(scope, scope.engine->metaTypeToJS(fromType, from));
160 *
static_cast<QJSValue *>(to) = QJSValuePrivate::fromReturnedValue(v->asReturnedValue());
164 if (toType == QMetaType::fromType<QJSManagedValue>()) {
168 QV4::Scope scope(engine);
169 QV4::ScopedValue v(scope, scope.engine->metaTypeToJS(fromType, from));
170 *
static_cast<QJSManagedValue *>(to) = QJSManagedValue(
171 QJSValuePrivate::fromReturnedValue(v->asReturnedValue()), engine->jsEngine());
181 const QtPrivate::QMetaTypeInterface *iface = type.iface();
182 QVariant::Private *d = &variant->data_ptr();
183 Q_ASSERT(d->is_null && !d->is_shared);
184 *d = QVariant::Private(iface);
185 if (QVariant::Private::canUseInternalSpace(iface))
190 d->data.shared = QVariant::PrivateShared::create(iface->size, iface->alignment);
192 return d->data.shared->data();
196 const QMetaObject *targetMetaObject,
int i,
void **args,
int argc,
void *target)
198 Q_ALLOCA_VAR(
void *, p, (argc + 1) *
sizeof(
void *));
200 memcpy(p + 1, args, argc *
sizeof(
void *));
201 targetMetaObject->static_metacall(QMetaObject::ConstructInPlace, i, p);
205 const QMetaObject *targetMetaObject,
int i,
void *source,
void *target)
207 void *p[] = { target, source };
208 targetMetaObject->static_metacall(QMetaObject::ConstructInPlace, i, p);
212template<
typename Allocate>
214 const QMetaObject *targetMetaObject,
int ctorIndex,
void **args,
217 const QMetaMethod ctor = targetMetaObject->constructor(ctorIndex);
218 callConstructor(targetMetaObject, ctorIndex, args, ctor.parameterCount(), allocate());
222template<
typename Allocate,
typename Retrieve>
224 const QMetaObject *targetMetaObject, Allocate &&allocate, Retrieve &&retrieve,
225 QV4::ExecutionEngine *engine)
227 const int end = targetMetaObject->constructorCount();
228 for (
int i = 0; i < end; ++i) {
230 const QMetaMethod ctor = targetMetaObject->constructor(i);
231 if (ctor.parameterCount() != 1)
234 if (retrieve([&](QMetaType sourceMetaType,
void *sourceData) {
235 if (sourceMetaType != ctor.parameterMetaType(0))
237 callConstructor(targetMetaObject, i, sourceData, allocate());
244 for (
int i = 0; i < end; ++i) {
246 const QMetaMethod ctor = targetMetaObject->constructor(i);
247 if (ctor.parameterCount() != 1)
250 const QMetaType parameterType = ctor.parameterMetaType(0);
251 const QMetaObject *parameterMetaObject = parameterType.metaObject();
252 if (!parameterMetaObject)
255 if (retrieve([&](QMetaType sourceMetaType,
void *sourceData) {
256 Q_ASSERT(sourceMetaType != parameterType);
257 if (
const QMetaObject *sourceMetaObject = sourceMetaType.metaObject();
258 sourceMetaObject && sourceMetaObject->inherits(parameterMetaObject)) {
259 callConstructor(targetMetaObject, i, sourceData, allocate());
268 for (
int i = 0; i < end; ++i) {
272 const QMetaMethod ctor = targetMetaObject->constructor(i);
273 if (ctor.parameterCount() != 1)
276 const QMetaType parameterType = ctor.parameterMetaType(0);
278 if (retrieve([&](QMetaType sourceMetaType,
void *sourceData) {
279 QVariant converted(parameterType);
280 if (coerceValue(sourceMetaType, sourceData, parameterType, converted.data(), engine)) {
281 callConstructor(targetMetaObject, i, converted.data(), allocate());
294template<
typename Allocate>
296 const QMetaObject *targetMetaObject,
const QV4::Value &source, Allocate &&allocate,
297 QV4::ExecutionEngine *engine)
300 return fromMatchingType(targetMetaObject, std::forward<Allocate>(allocate), [&](
auto callback) {
301 if (!variant.isValid())
302 variant = QV4::ExecutionEngine::toVariant(source, QMetaType());
303 return callback(variant.metaType(), variant.data());
307template<
typename Allocate>
309 const QMetaObject *targetMetaObject, QVariant source, Allocate &&allocate,
310 QV4::ExecutionEngine *engine)
312 return fromMatchingType(targetMetaObject, std::forward<Allocate>(allocate), [&](
auto callback) {
313 return callback(source.metaType(), source.data());
317template<
typename Allocate>
318static bool fromString(
const QMetaObject *mo, QString s, Allocate &&allocate)
320 for (
int i = 0, end = mo->constructorCount(); i < end; ++i) {
321 const QMetaMethod ctor = mo->constructor(i);
322 if (ctor.parameterCount() != 1)
325 if (ctor.parameterMetaType(0) == QMetaType::fromType<QString>()) {
326 callConstructor(mo, i, &s, allocate());
334template<
typename Get,
typename Convert>
336 const QMetaProperty &metaProperty,
void *target, Get &&get, Convert &&convert,
337 QV4::ExecutionEngine *engine)
339 const QMetaType propertyType = metaProperty.metaType();
340 QVariant property = get(propertyType);
341 if (property.metaType() == propertyType) {
342 metaProperty.writeOnGadget(target, std::move(property));
346 QVariant converted = convert(propertyType);
347 if (converted.isValid()) {
348 metaProperty.writeOnGadget(target, std::move(converted));
352 converted = QVariant(propertyType);
354 property.metaType(), property.constData(), propertyType, converted.data(),
356 metaProperty.writeOnGadget(target, std::move(converted));
364 const QMetaObject *targetMetaObject,
void *target,
const QV4::Value &source,
365 QV4::ExecutionEngine *engine)
367 const QV4::Object *o =
static_cast<
const QV4::Object *>(&source);
368 QV4::Scope scope(o->engine());
369 QV4::ScopedObject object(scope, o);
371 for (
int i = 0; i < targetMetaObject->propertyCount(); ++i) {
372 const QMetaProperty metaProperty = targetMetaObject->property(i);
373 const QString propertyName = QString::fromUtf8(metaProperty.name());
375 QV4::ScopedString v4PropName(scope, scope.engine->newString(propertyName));
376 QV4::ScopedValue v4PropValue(scope, object->get(v4PropName));
380 if (v4PropValue->isUndefined())
383 if (doWriteProperty(metaProperty, target, [&](
const QMetaType &propertyType) {
384 return QV4::ExecutionEngine::toVariant(v4PropValue, propertyType);
385 }, [&](
const QMetaType &propertyType) {
386 return QQmlValueTypeProvider::createValueType(v4PropValue, propertyType, engine);
391 const QMetaType propertyType = metaProperty.metaType();
392 QVariant property = QV4::ExecutionEngine::toVariant(v4PropValue, propertyType);
393 if (property.metaType() == propertyType) {
394 metaProperty.writeOnGadget(target, std::move(property));
398 QVariant converted = QQmlValueTypeProvider::createValueType(
399 v4PropValue, propertyType, engine);
400 if (converted.isValid()) {
401 metaProperty.writeOnGadget(target, std::move(converted));
405 converted = QVariant(propertyType);
407 property.metaType(), property.constData(), propertyType, converted.data(),
409 metaProperty.writeOnGadget(target, std::move(converted));
413 printConversionWarning(engine, v4PropValue->toQStringNoThrow(),
414 QString::fromUtf8(propertyType.name()), propertyName);
419 const QMetaObject *targetMetaObject, QMetaType metaType,
const QV4::Value &source,
420 QV4::ExecutionEngine *engine)
422 if (!source.isObject() || !targetMetaObject)
425 QVariant result(metaType);
426 doWriteProperties(targetMetaObject, result.data(), source, engine);
430template<
typename Read>
432 const QMetaObject *targetMetaObject,
void *target,
433 const QMetaObject *sourceMetaObject, Read &&read, QV4::ExecutionEngine *engine)
435 for (
int i = 0; i < targetMetaObject->propertyCount(); ++i) {
436 const QMetaProperty metaProperty = targetMetaObject->property(i);
438 const int sourceProperty = sourceMetaObject->indexOfProperty(metaProperty.name());
442 if (sourceProperty == -1)
445 const QMetaType propertyType = metaProperty.metaType();
446 QVariant property = read(sourceMetaObject, sourceProperty);
447 if (property.metaType() == propertyType) {
448 metaProperty.writeOnGadget(target, std::move(property));
452 QVariant converted = QQmlValueTypeProvider::createValueType(property, propertyType, engine);
453 if (converted.isValid()) {
454 metaProperty.writeOnGadget(target, std::move(converted));
458 converted = QVariant(propertyType);
460 property.metaType(), property.constData(), propertyType, converted.data(),
462 metaProperty.writeOnGadget(target, std::move(converted));
466 printConversionWarning(engine, QDebug::toString(property),
467 QString::fromUtf8(propertyType.name()),
468 QString::fromUtf8(metaProperty.name()));
474 const QMetaObject *targetMeta,
void *target, QObject *source, QV4::ExecutionEngine *engine)
477 targetMeta, target, source->metaObject(),
478 [source](
const QMetaObject *sourceMetaObject,
int sourceProperty) {
479 return sourceMetaObject->property(sourceProperty).read(source);
484 const QMetaObject *targetMetaObject, QMetaType targetMetaType, QObject *source,
485 QV4::ExecutionEngine *engine)
487 if (!source || !targetMetaObject)
490 QVariant result(targetMetaType);
491 doWriteProperties(targetMetaObject, result.data(), source, engine);
496 const QMetaObject *targetMetaObject, QMetaType targetMetaType,
497 const QMetaObject *sourceMetaObject,
const void *source, QV4::ExecutionEngine *engine)
499 if (!source || !sourceMetaObject || !targetMetaObject)
502 QVariant result(targetMetaType);
504 targetMetaObject, result.data(), sourceMetaObject,
505 [source](
const QMetaObject *sourceMetaObject,
int sourceProperty) {
506 return sourceMetaObject->property(sourceProperty).readOnGadget(source);
511template<
typename Map>
513 const QMetaObject *targetMetaObject,
void *target,
const Map &source,
514 QV4::ExecutionEngine *engine)
516 for (
int i = 0; i < targetMetaObject->propertyCount(); ++i) {
517 const QMetaProperty metaProperty = targetMetaObject->property(i);
521 const auto it = source.constFind(QString::fromUtf8(metaProperty.name()));
522 if (it == source.constEnd())
525 const QMetaType propertyType = metaProperty.metaType();
526 QVariant property = *it;
527 if (property.metaType() == propertyType) {
528 metaProperty.writeOnGadget(target, std::move(property));
532 QVariant converted = QQmlValueTypeProvider::createValueType(property, propertyType, engine);
533 if (converted.isValid()) {
534 metaProperty.writeOnGadget(target, std::move(converted));
538 converted = QVariant(propertyType);
540 property.metaType(), property.constData(), propertyType, converted.data(),
542 metaProperty.writeOnGadget(target, std::move(converted));
546 printConversionWarning(engine, QDebug::toString(property),
547 QString::fromUtf8(propertyType.name()),
548 QString::fromUtf8(metaProperty.name()));
552template<
typename Map>
554 const QMetaObject *targetMetaObject, QMetaType targetMetaType,
const Map &source,
555 QV4::ExecutionEngine *engine)
557 QVariant result(targetMetaType);
558 doWriteProperties(targetMetaObject, result.data(), source, engine);
563 const QMetaObject *targetMetaObject, QMetaType targetMetaType,
const QVariant &source,
564 QV4::ExecutionEngine *engine)
566 if (!targetMetaObject)
569 if (source.metaType() == QMetaType::fromType<QJSValue>()) {
570 QJSValue val = source.value<QJSValue>();
576 targetMetaObject, targetMetaType,
577 QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(&val)),
581 if (source.metaType() == QMetaType::fromType<QVariantMap>()) {
583 targetMetaObject, targetMetaType,
584 *
static_cast<
const QVariantMap *>(source.constData()), engine);
587 if (source.metaType() == QMetaType::fromType<QVariantHash>()) {
589 targetMetaObject, targetMetaType,
590 *
static_cast<
const QVariantHash *>(source.constData()), engine);
593 if (source.metaType().flags() & QMetaType::PointerToQObject)
594 return byProperties(targetMetaObject, targetMetaType, source.value<QObject *>(), engine);
596 if (
const QMetaObject *sourceMeta = QQmlMetaType::metaObjectForValueType(source.metaType())) {
598 targetMetaObject, targetMetaType, sourceMeta, source.constData(), engine);
604template<
typename Allocate,
typename DefaultConstruct>
606 const QQmlType &targetType,
const QV4::Value &source,
607 Allocate &&allocate, DefaultConstruct &&defaultConstruct, QV4::ExecutionEngine *engine)
609 const auto warn = [&](
const QMetaObject *targetMetaObject) {
611 <<
"Could not find any constructor for value type"
612 << targetMetaObject->className() <<
"to call with value"
613 << source.toQStringNoThrow();
616 if (targetType.canPopulateValueType()) {
617 if (
const QMetaObject *targetMetaObject = targetType.metaObjectForValueType()) {
618 if (source.isObject()) {
619 doWriteProperties(targetMetaObject, defaultConstruct(), source, engine);
622 if (targetType.canConstructValueType()) {
623 if (fromMatchingType(targetMetaObject, source, allocate, engine))
625 warn(targetMetaObject);
628 }
else if (targetType.canConstructValueType()) {
629 if (
const QMetaObject *targetMetaObject = targetType.metaObjectForValueType()) {
630 if (fromMatchingType(targetMetaObject, source, allocate, engine))
632 warn(targetMetaObject);
636 if (
const auto valueTypeFunction = targetType.createValueTypeFunction()) {
637 const QVariant result
638 = valueTypeFunction(QJSValuePrivate::fromReturnedValue(source.asReturnedValue()));
639 const QMetaType resultType = result.metaType();
640 if (resultType == targetType.typeId()) {
641 resultType.construct(allocate(), result.constData());
649template<
typename Allocate,
typename DefaultConstruct>
651 const QQmlType &targetType, QMetaType sourceMetaType,
void *source,
652 Allocate &&allocate, DefaultConstruct &&defaultConstruct, QV4::ExecutionEngine *engine)
655 const auto warn = [&](
const QMetaObject *targetMetaObject) {
657 <<
"Could not find any constructor for value type"
658 << targetMetaObject->className() <<
"to call with value" << source;
661 if (targetType.canPopulateValueType()) {
662 if (
const QMetaObject *targetMetaObject = targetType.metaObjectForValueType()) {
663 if (
const QMetaObject *sourceMetaObject
664 = QQmlMetaType::metaObjectForValueType(sourceMetaType)) {
666 targetMetaObject, defaultConstruct(), sourceMetaObject,
667 [&source](
const QMetaObject *sourceMetaObject,
int sourceProperty) {
668 return sourceMetaObject->property(sourceProperty).readOnGadget(source);
673 if (sourceMetaType == QMetaType::fromType<QVariantMap>()) {
675 targetMetaObject, defaultConstruct(),
676 *
static_cast<
const QVariantMap *>(source), engine);
680 if (sourceMetaType == QMetaType::fromType<QVariantHash>()) {
682 targetMetaObject, defaultConstruct(),
683 *
static_cast<
const QVariantHash *>(source), engine);
687 if (sourceMetaType.flags() & QMetaType::PointerToQObject) {
689 targetMetaObject, defaultConstruct(),
690 *
static_cast<QObject *
const *>(source), engine);
696 if (targetType.canConstructValueType()) {
697 if (
const QMetaObject *targetMetaObject = targetType.metaObjectForValueType()) {
698 if (fromMatchingType(
699 targetMetaObject, std::forward<Allocate>(allocate), [&](
auto callback) {
700 return callback(sourceMetaType, source);
704 warn(targetMetaObject);
712
713
714
715
716
717
718
719bool QQmlValueTypeProvider::populateValueType(
720 QMetaType targetMetaType,
void *target, QMetaType sourceMetaType,
void *source,
721 QV4::ExecutionEngine *engine)
723 if (sourceMetaType == QMetaType::fromType<QJSValue>()) {
724 const QJSValue *val =
static_cast<
const QJSValue *>(source);
729 return populateValueType(
730 targetMetaType, target,
731 QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(val)),
735 if (!isConstructibleMetaType(targetMetaType))
738 return createOrConstructValueType(
739 QQmlMetaType::qmlType(targetMetaType), sourceMetaType, source,
740 [targetMetaType, target]() {
741 targetMetaType.destruct(target);
749
750
751
752
753
754
755
756bool QQmlValueTypeProvider::populateValueType(
757 QMetaType targetMetaType,
void *target,
const QV4::Value &source,
758 QV4::ExecutionEngine *engine)
760 if (!isConstructibleMetaType(targetMetaType))
763 return createOrConstructValueType(
764 QQmlMetaType::qmlType(targetMetaType), source, [targetMetaType, target]() {
765 targetMetaType.destruct(target);
773
774
775
776void *QQmlValueTypeProvider::heapCreateValueType(
777 const QQmlType &targetType,
const QV4::Value &source, QV4::ExecutionEngine *engine)
779 void *target =
nullptr;
780 if (createOrConstructValueType(
781 targetType, source, [&]() {
782 const QMetaType metaType = targetType.typeId();
783 const ushort align = metaType.alignOf();
784 target = align > __STDCPP_DEFAULT_NEW_ALIGNMENT__
785 ? operator
new(metaType.sizeOf(), std::align_val_t(align))
786 : operator
new(metaType.sizeOf());
789 target = targetType.typeId().create();
792 Q_ASSERT(target !=
nullptr);
798QVariant QQmlValueTypeProvider::constructValueType(
799 QMetaType targetMetaType,
const QMetaObject *targetMetaObject,
800 int ctorIndex,
void **args)
803 fromVerifiedType(targetMetaObject, ctorIndex, args,
804 [&]() {
return createVariantData(targetMetaType, &result); });
810 if (
const auto valueTypeFunction = type.createValueTypeFunction()) {
811 const QVariant result = valueTypeFunction(s);
812 if (result.metaType() == metaType)
819QVariant QQmlValueTypeProvider::createValueType(
const QJSValue &s, QMetaType metaType)
821 if (!isConstructibleMetaType(metaType))
823 return fromJSValue(QQmlMetaType::qmlType(metaType), s, metaType);
826QVariant QQmlValueTypeProvider::createValueType(
const QString &s, QMetaType metaType)
828 if (!isConstructibleMetaType(metaType))
830 const QQmlType type = QQmlMetaType::qmlType(metaType);
831 if (type.canConstructValueType()) {
832 if (
const QMetaObject *mo = type.metaObjectForValueType()) {
834 if (fromString(mo, s, [&]() {
return createVariantData(metaType, &result); }))
839 return fromJSValue(type, s, metaType);
842QVariant QQmlValueTypeProvider::createValueType(
843 const QV4::Value &s, QMetaType metaType, QV4::ExecutionEngine *engine)
845 if (!isConstructibleMetaType(metaType))
847 const QQmlType type = QQmlMetaType::qmlType(metaType);
848 const auto warn = [&](
const QMetaObject *mo) {
850 <<
"Could not find any constructor for value type"
851 << mo->className() <<
"to call with value" << s.toQStringNoThrow();
854 if (type.canPopulateValueType()) {
855 if (
const QMetaObject *mo = type.metaObject()) {
856 QVariant result = byProperties(mo, metaType, s, engine);
857 if (result.isValid())
859 if (type.canConstructValueType()) {
860 if (fromMatchingType(
861 mo, s, [&]() {
return createVariantData(metaType, &result); },
868 }
else if (type.canConstructValueType()) {
869 if (
const QMetaObject *mo = type.metaObject()) {
871 if (fromMatchingType(
872 mo, s, [&]() {
return createVariantData(metaType, &result); },
880 return fromJSValue(type, QJSValuePrivate::fromReturnedValue(s.asReturnedValue()), metaType);
885
886
887
888QVariant QQmlValueTypeProvider::createValueType(
889 const QVariant &s, QMetaType metaType, QV4::ExecutionEngine *engine)
891 if (!isConstructibleMetaType(metaType))
893 const QQmlType type = QQmlMetaType::qmlType(metaType);
894 const auto warn = [&](
const QMetaObject *mo) {
896 <<
"Could not find any constructor for value type"
897 << mo->className() <<
"to call with value" << s;
900 if (type.canPopulateValueType()) {
901 if (
const QMetaObject *mo = type.metaObjectForValueType()) {
902 QVariant result = byProperties(mo, metaType, s, engine);
903 if (result.isValid())
905 if (type.canConstructValueType()) {
906 if (fromMatchingType(
907 mo, s, [&]() {
return createVariantData(metaType, &result); },
914 }
else if (type.canConstructValueType()) {
915 if (
const QMetaObject *mo = type.metaObjectForValueType()) {
917 if (fromMatchingType(
918 mo, s, [&]() {
return createVariantData(metaType, &result); },
929QQmlColorProvider::~QQmlColorProvider() {}
930QVariant QQmlColorProvider::colorFromString(
const QString &,
bool *ok) {
if (ok) *ok =
false;
return QVariant(); }
931unsigned QQmlColorProvider::rgbaFromString(
const QString &,
bool *ok) {
if (ok) *ok =
false;
return 0; }
932QVariant QQmlColorProvider::fromRgbF(
double,
double,
double,
double) {
return QVariant(); }
933QVariant QQmlColorProvider::fromHslF(
double,
double,
double,
double) {
return QVariant(); }
934QVariant QQmlColorProvider::fromHsvF(
double,
double,
double,
double) {
return QVariant(); }
935QVariant QQmlColorProvider::lighter(
const QVariant &, qreal) {
return QVariant(); }
936QVariant QQmlColorProvider::darker(
const QVariant &, qreal) {
return QVariant(); }
937QVariant QQmlColorProvider::alpha(
const QVariant &, qreal)
941QVariant QQmlColorProvider::tint(
const QVariant &,
const QVariant &) {
return QVariant(); }
947 QQmlColorProvider *old = colorProvider;
948 colorProvider = newProvider;
955 qWarning() <<
"Warning: QQml_colorProvider: no color provider has been set!";
956 static QQmlColorProvider nullColorProvider;
960 return &colorProvider;
965 static QQmlColorProvider **providerPtr = getColorProvider();
970QQmlGuiProvider::~QQmlGuiProvider() {}
971QQmlApplication *QQmlGuiProvider::application(QObject *parent)
973 return new QQmlApplication(parent);
975QStringList QQmlGuiProvider::fontFamilies() {
return QStringList(); }
976bool QQmlGuiProvider::openUrlExternally(
const QUrl &) {
return false; }
978QObject *QQmlGuiProvider::inputMethod()
981 QObject *o =
new QObject();
982 o->setObjectName(QStringLiteral(
"No inputMethod available"));
983 QQmlEngine::setObjectOwnership(o, QQmlEngine::JavaScriptOwnership);
987QObject *QQmlGuiProvider::styleHints()
989 QObject *o =
new QObject();
990 o->setObjectName(QStringLiteral(
"No styleHints available"));
991 QQmlEngine::setObjectOwnership(o, QQmlEngine::JavaScriptOwnership);
995QString QQmlGuiProvider::pluginName()
const {
return QString(); }
1001 QQmlGuiProvider *old = guiProvider;
1002 guiProvider = newProvider;
1009 static QQmlGuiProvider nullGuiProvider;
1013 return &guiProvider;
1018 static QQmlGuiProvider **providerPtr = getGuiProvider();
1019 return *providerPtr;
1023QQmlApplication::QQmlApplication(QObject *parent)
1024 : QQmlApplication(*(
new QQmlApplicationPrivate), parent)
1028QQmlApplication::QQmlApplication(QQmlApplicationPrivate &dd, QObject *parent)
1029 : QObject(dd, parent)
1031 connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
1032 this, SIGNAL(aboutToQuit()));
1033 connect(QCoreApplication::instance(), SIGNAL(applicationNameChanged()),
1034 this, SIGNAL(nameChanged()));
1035 connect(QCoreApplication::instance(), SIGNAL(applicationVersionChanged()),
1036 this, SIGNAL(versionChanged()));
1037 connect(QCoreApplication::instance(), SIGNAL(organizationNameChanged()),
1038 this, SIGNAL(organizationChanged()));
1039 connect(QCoreApplication::instance(), SIGNAL(organizationDomainChanged()),
1040 this, SIGNAL(domainChanged()));
1043QStringList QQmlApplication::args()
1045 Q_D(QQmlApplication);
1048 d->args = QCoreApplication::arguments();
1053QString QQmlApplication::name()
const
1055 return QCoreApplication::instance()->applicationName();
1058QString QQmlApplication::version()
const
1060 return QCoreApplication::instance()->applicationVersion();
1063QString QQmlApplication::organization()
const
1065 return QCoreApplication::instance()->organizationName();
1068QString QQmlApplication::domain()
const
1070 return QCoreApplication::instance()->organizationDomain();
1073void QQmlApplication::setName(
const QString &arg)
1075 QCoreApplication::instance()->setApplicationName(arg);
1078void QQmlApplication::setVersion(
const QString &arg)
1080 QCoreApplication::instance()->setApplicationVersion(arg);
1083void QQmlApplication::setOrganization(
const QString &arg)
1085 QCoreApplication::instance()->setOrganizationName(arg);
1088void QQmlApplication::setDomain(
const QString &arg)
1090 QCoreApplication::instance()->setOrganizationDomain(arg);
1096 auto ddata = QQmlData::get(object,
false);
1097 return (ddata && ddata->propertyCache) ? ddata :
nullptr;
1103 if (
const QQmlData *ddata = ddata_for_cast(object))
1104 return ddata->propertyCache->firstCppMetaObject()->inherits(mo);
1105 return object->metaObject()->inherits(mo);
1110 Q_ASSERT(type.isValid());
1113 const QMetaObject *typeMetaObject = type.metaObject();
1114 const QQmlPropertyCache::ConstPtr typePropertyCache = typeMetaObject
1115 ? QQmlPropertyCache::ConstPtr()
1116 : QQmlMetaType::findPropertyCacheInCompositeTypes(type.typeId());
1118 if (
const QQmlData *ddata = ddata_for_cast(object)) {
1119 for (
const QQmlPropertyCache *propertyCache = ddata->propertyCache.data(); propertyCache;
1120 propertyCache = propertyCache->parent().data()) {
1122 if (typeMetaObject) {
1129 if (
const QMetaObject *objectMetaObject = propertyCache->metaObject())
1130 return objectMetaObject->inherits(typeMetaObject);
1136 if (propertyCache == typePropertyCache.data())
1144 return object->metaObject()->inherits(typeMetaObject
1146 : (typePropertyCache ? typePropertyCache->createMetaObject() :
nullptr));
1151#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)