Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqmlglobal.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 <QtQml/private/qjsvalue_p.h>
5#include <QtQml/private/qqmlglobal_p.h>
6#include <QtQml/private/qqmlmetatype_p.h>
7#include <QtQml/qqmlengine.h>
8
9#include <QtCore/private/qvariant_p.h>
10#include <QtCore/qcoreapplication.h>
11#include <QtCore/qdebug.h>
12#include <QtCore/qstringlist.h>
13
15
16// Pre-filter the metatype before poking QQmlMetaType::qmlType() and locking its mutex.
17static bool isConstructibleMetaType(const QMetaType metaType)
18{
19 switch (metaType.id()) {
20 // The builtins are not constructible this way.
21 case QMetaType::Void:
22 case QMetaType::Nullptr:
24 case QMetaType::Int:
25 case QMetaType::UInt:
26 case QMetaType::LongLong:
27 case QMetaType::ULongLong:
28 case QMetaType::Float:
29 case QMetaType::Double:
30 case QMetaType::Long:
31 case QMetaType::ULong:
32 case QMetaType::Short:
33 case QMetaType::UShort:
34 case QMetaType::Char:
35 case QMetaType::SChar:
36 case QMetaType::UChar:
37 case QMetaType::QChar:
38 case QMetaType::QString:
39 case QMetaType::Bool:
40 case QMetaType::QDateTime:
41 case QMetaType::QDate:
42 case QMetaType::QTime:
43 case QMetaType::QUrl:
44 case QMetaType::QRegularExpression:
45 case QMetaType::QByteArray:
46 case QMetaType::QLocale:
47 return false;
48 default:
49 break;
50 }
51
52 // QJSValue is also builtin
53 if (metaType == QMetaType::fromType<QJSValue>())
54 return false;
55
56 // We also don't want to construct pointers of any kind, or lists, or enums.
57 if (metaType.flags() &
67 return false;
68 }
69
70 return true;
71}
72
74{
75 const QtPrivate::QMetaTypeInterface *iface = type.iface();
77 Q_ASSERT(d->is_null && !d->is_shared);
78 *d = QVariant::Private(iface);
80 return d->data.data;
81
82 // This is not exception safe.
83 // If your value type throws an exception from its ctor bad things will happen anyway.
84 d->data.shared = QVariant::PrivateShared::create(iface->size, iface->alignment);
85 d->is_shared = true;
86 return d->data.shared->data();
87}
88
89static void callConstructor(
90 const QMetaObject *targetMetaObject, int i, void *source, void *target)
91{
92 void *p[] = { target, source };
94}
95
96template<typename Allocate>
97static void fromVerifiedType(
98 const QMetaObject *targetMetaObject, int ctorIndex, void *source, Allocate &&allocate)
99{
100 const QMetaMethod ctor = targetMetaObject->constructor(ctorIndex);
101 Q_ASSERT_X(ctor.parameterCount() == 1, "fromVerifiedType",
102 "Value type constructor must take exactly one argument");
103 callConstructor(targetMetaObject, ctorIndex, source, allocate());
104}
105
106
107template<typename Allocate, typename Retrieve>
109 const QMetaObject *targetMetaObject, Allocate &&allocate, Retrieve &&retrieve)
110{
111 for (int i = 0, end = targetMetaObject->constructorCount(); i < end; ++i) {
112 const QMetaMethod ctor = targetMetaObject->constructor(i);
113 if (ctor.parameterCount() != 1)
114 continue;
115
116 const QMetaType parameterType = ctor.parameterMetaType(0);
117
118 if (retrieve(parameterType, [&](QMetaType sourceMetaType, void *sourceData) {
119 if (sourceMetaType == parameterType) {
120 callConstructor(targetMetaObject, i, sourceData, allocate());
121 return true;
122 }
123
124 if (const QMetaObject *parameterMetaObject = parameterType.metaObject()) {
125 if (const QMetaObject *sourceMetaObject = sourceMetaType.metaObject();
126 sourceMetaObject && sourceMetaObject->inherits(parameterMetaObject)) {
127 // Allow construction from derived types.
128 callConstructor(targetMetaObject, i, sourceData, allocate());
129 return true;
130 }
131 }
132
133 // Do not recursively try to create parameters here. This may end up in infinite recursion.
134
135 // At this point, s should be a builtin type. For builtin types
136 // the QMetaType converters are good enough.
137 QVariant converted(parameterType);
138 if (QMetaType::convert(sourceMetaType, sourceData, parameterType, converted.data())) {
139 callConstructor(targetMetaObject, i, converted.data(), allocate());
140 return true;
141 }
142
143 return false;
144 })) {
145 return true;
146 }
147 }
148
149 return false;
150}
151
152template<typename Allocate>
154 const QMetaObject *targetMetaObject, const QV4::Value &source, Allocate &&allocate)
155{
156 return fromMatchingType(
157 targetMetaObject, std::forward<Allocate>(allocate),
158 [&](QMetaType parameterType, auto callback) {
160 return callback(variant.metaType(), variant.data());
161 });
162}
163
164template<typename Allocate>
166 const QMetaObject *targetMetaObject, QVariant source, Allocate &&allocate)
167{
168 return fromMatchingType(targetMetaObject, std::forward<Allocate>(allocate),
169 [&](QMetaType, auto callback) {
170 return callback(source.metaType(), source.data());
171 });
172}
173
174template<typename Allocate>
175static bool fromString(const QMetaObject *mo, QString s, Allocate &&allocate)
176{
177 for (int i = 0, end = mo->constructorCount(); i < end; ++i) {
178 const QMetaMethod ctor = mo->constructor(i);
179 if (ctor.parameterCount() != 1)
180 continue;
181
182 if (ctor.parameterMetaType(0) == QMetaType::fromType<QString>()) {
183 callConstructor(mo, i, &s, allocate());
184 return true;
185 }
186 }
187
188 return false;
189}
190
191template<typename Get, typename Convert>
192static bool doWriteProperty(const QMetaProperty &metaProperty, void *target,
193 Get &&get, Convert &&convert)
194{
195 const QMetaType propertyType = metaProperty.metaType();
196 QVariant property = get(propertyType);
197 if (property.metaType() == propertyType) {
198 metaProperty.writeOnGadget(target, std::move(property));
199 return true;
200 }
201
202 QVariant converted = convert(propertyType);
203 if (converted.isValid()) {
204 metaProperty.writeOnGadget(target, std::move(converted));
205 return true;
206 }
207
208 converted = QVariant(propertyType);
209 if (QMetaType::convert(property.metaType(), property.constData(),
210 propertyType, converted.data())) {
211 metaProperty.writeOnGadget(target, std::move(converted));
212 return true;
213 }
214
215 return false;
216}
217
219 const QMetaObject *targetMetaObject, void *target, const QV4::Value &source)
220{
221 const QV4::Object *o = static_cast<const QV4::Object *>(&source);
222 QV4::Scope scope(o->engine());
223 QV4::ScopedObject object(scope, o);
224
225 for (int i = 0; i < targetMetaObject->propertyCount(); ++i) {
226 const QMetaProperty metaProperty = targetMetaObject->property(i);
227 const QString propertyName = QString::fromUtf8(metaProperty.name());
228
229 QV4::ScopedString v4PropName(scope, scope.engine->newString(propertyName));
230 QV4::ScopedValue v4PropValue(scope, object->get(v4PropName));
231
232 // We assume that data is freshly constructed.
233 // There is no point in reset()'ing properties of a freshly created object.
234 if (v4PropValue->isUndefined())
235 continue;
236
237 if (doWriteProperty(metaProperty, target, [&](const QMetaType &propertyType) {
238 return QV4::ExecutionEngine::toVariant(v4PropValue, propertyType);
239 }, [&](const QMetaType &propertyType) {
240 return QQmlValueTypeProvider::createValueType(v4PropValue, propertyType);
241 })) {
242 continue;
243 }
244
245 const QMetaType propertyType = metaProperty.metaType();
246 QVariant property = QV4::ExecutionEngine::toVariant(v4PropValue, propertyType);
247 if (property.metaType() == propertyType) {
248 metaProperty.writeOnGadget(target, std::move(property));
249 continue;
250 }
251
252 QVariant converted = QQmlValueTypeProvider::createValueType(v4PropValue, propertyType);
253 if (converted.isValid()) {
254 metaProperty.writeOnGadget(target, std::move(converted));
255 continue;
256 }
257
258 converted = QVariant(propertyType);
259 if (QMetaType::convert(property.metaType(), property.constData(),
260 propertyType, converted.data())) {
261 metaProperty.writeOnGadget(target, std::move(converted));
262 continue;
263 }
264
265 qWarning().noquote()
266 << QLatin1String("Could not convert %1 to %2 for property %3")
267 .arg(v4PropValue->toQStringNoThrow(), QString::fromUtf8(propertyType.name()),
268 propertyName);
269 }
270}
271
273 const QMetaObject *targetMetaObject, QMetaType metaType, const QV4::Value &source)
274{
275 if (!source.isObject() || !targetMetaObject)
276 return QVariant();
277
278 QVariant result(metaType);
279 doWriteProperties(targetMetaObject, result.data(), source);
280 return result;
281}
282
283template<typename Read>
285 const QMetaObject *targetMetaObject, void *target,
286 const QMetaObject *sourceMetaObject, Read &&read)
287{
288 for (int i = 0; i < targetMetaObject->propertyCount(); ++i) {
289 const QMetaProperty metaProperty = targetMetaObject->property(i);
290
291 const int sourceProperty = sourceMetaObject->indexOfProperty(metaProperty.name());
292
293 // We assume that data is freshly constructed.
294 // There is no point in reset()'ing properties of a freshly created object.
295 if (sourceProperty == -1)
296 continue;
297
298 const QMetaType propertyType = metaProperty.metaType();
299 QVariant property = read(sourceMetaObject, sourceProperty);
300 if (property.metaType() == propertyType) {
301 metaProperty.writeOnGadget(target, std::move(property));
302 continue;
303 }
304
306 if (converted.isValid()) {
307 metaProperty.writeOnGadget(target, std::move(converted));
308 continue;
309 }
310
311 converted = QVariant(propertyType);
312 if (QMetaType::convert(property.metaType(), property.constData(),
313 propertyType, converted.data())) {
314 metaProperty.writeOnGadget(target, std::move(converted));
315 continue;
316 }
317
318 qWarning().noquote()
319 << QLatin1String("Could not convert %1 to %2 for property %3")
320 .arg(property.toString(), QString::fromUtf8(propertyType.name()),
321 QString::fromUtf8(metaProperty.name()));
322 }
323}
324
325
326static void doWriteProperties(const QMetaObject *targetMeta, void *target, QObject *source)
327{
329 targetMeta, target, source->metaObject(),
330 [source](const QMetaObject *sourceMetaObject, int sourceProperty) {
331 return sourceMetaObject->property(sourceProperty).read(source);
332 });
333}
334
336 const QMetaObject *targetMetaObject, QMetaType targetMetaType, QObject *source)
337{
338 if (!source || !targetMetaObject)
339 return QVariant();
340
341 QVariant result(targetMetaType);
342 doWriteProperties(targetMetaObject, result.data(), source);
343 return result;
344}
345
347 const QMetaObject *targetMetaObject, QMetaType targetMetaType,
348 const QMetaObject *sourceMetaObject, const void *source)
349{
350 if (!source || !sourceMetaObject || !targetMetaObject)
351 return QVariant();
352
353 QVariant result(targetMetaType);
355 targetMetaObject, result.data(), sourceMetaObject,
356 [source](const QMetaObject *sourceMetaObject, int sourceProperty) {
357 return sourceMetaObject->property(sourceProperty).readOnGadget(source);
358 });
359 return result;
360}
361
362template<typename Map>
363void doWriteProperties(const QMetaObject *targetMetaObject, void *target, const Map &source)
364{
365 for (int i = 0; i < targetMetaObject->propertyCount(); ++i) {
366 const QMetaProperty metaProperty = targetMetaObject->property(i);
367
368 // We assume that data is freshly constructed.
369 // There is no point in reset()'ing properties of a freshly created object.
370 const auto it = source.constFind(QString::fromUtf8(metaProperty.name()));
371 if (it == source.constEnd())
372 continue;
373
374 const QMetaType propertyType = metaProperty.metaType();
375 QVariant property = *it;
376 if (property.metaType() == propertyType) {
377 metaProperty.writeOnGadget(target, std::move(property));
378 continue;
379 }
380
382 if (converted.isValid()) {
383 metaProperty.writeOnGadget(target, std::move(converted));
384 continue;
385 }
386
387 converted = QVariant(propertyType);
388 if (QMetaType::convert(property.metaType(), property.constData(),
389 propertyType, converted.data())) {
390 metaProperty.writeOnGadget(target, std::move(converted));
391 continue;
392 }
393
394 qWarning().noquote()
395 << QLatin1String("Could not convert %1 to %2 for property %3")
396 .arg(property.toString(), QString::fromUtf8(propertyType.name()),
397 QString::fromUtf8(metaProperty.name()));
398 }
399}
400
401template<typename Map>
403 const QMetaObject *targetMetaObject, QMetaType targetMetaType, const Map &source)
404{
405 QVariant result(targetMetaType);
406 doWriteProperties(targetMetaObject, result.data(), source);
407 return result;
408}
409
411 const QMetaObject *targetMetaObject, QMetaType targetMetaType, const QVariant &source)
412{
413 if (!targetMetaObject)
414 return QVariant();
415
416 if (source.metaType() == QMetaType::fromType<QJSValue>()) {
417 QJSValue val = source.value<QJSValue>();
418 return byProperties(
419 targetMetaObject, targetMetaType, QV4::Value(QJSValuePrivate::asReturnedValue(&val)));
420 }
421
422 if (source.metaType() == QMetaType::fromType<QVariantMap>()) {
423 return byProperties(
424 targetMetaObject, targetMetaType,
425 *static_cast<const QVariantMap *>(source.constData()));
426 }
427
428 if (source.metaType() == QMetaType::fromType<QVariantHash>()) {
429 return byProperties(
430 targetMetaObject, targetMetaType,
431 *static_cast<const QVariantHash *>(source.constData()));
432 }
433
434 if (source.metaType().flags() & QMetaType::PointerToQObject)
435 return byProperties(targetMetaObject, targetMetaType, source.value<QObject *>());
436
437 if (const QMetaObject *sourceMeta = QQmlMetaType::metaObjectForValueType(source.metaType()))
438 return byProperties(targetMetaObject, targetMetaType, sourceMeta, source.constData());
439
440 return QVariant();
441}
442
443template<typename Allocate, typename DefaultConstruct>
445 const QQmlType &targetType, const QV4::Value &source,
446 Allocate &&allocate, DefaultConstruct &&defaultConstruct)
447{
448 if (const QMetaObject *targetMetaObject = QQmlMetaType::metaObjectForValueType(targetType)) {
449 const auto warn = [&]() {
450 qWarning().noquote()
451 << "Could not find any constructor for value type"
452 << targetMetaObject->className() << "to call with value"
453 << source.toQStringNoThrow();
454 };
455
456 if (targetType.canPopulateValueType()) {
457 if (source.isObject() && targetMetaObject) {
458 doWriteProperties(targetMetaObject, defaultConstruct(), source);
459 return true;
460 }
461 if (targetType.canConstructValueType()) {
462 if (fromMatchingType(targetMetaObject, source, allocate))
463 return true;
464 warn();
465
466 }
467 } else if (targetType.canConstructValueType()) {
468 if (fromMatchingType(targetMetaObject, source, allocate))
469 return true;
470 warn();
471 }
472 }
473
474 if (const auto valueTypeFunction = targetType.createValueTypeFunction()) {
475 const QVariant result
476 = valueTypeFunction(QJSValuePrivate::fromReturnedValue(source.asReturnedValue()));
477 const QMetaType resultType = result.metaType();
478 if (resultType == targetType.typeId()) {
479 resultType.construct(allocate(), result.constData());
480 return true;
481 }
482 }
483
484 return false;
485}
486
487template<typename Allocate, typename DefaultConstruct>
489 const QQmlType &targetType, QMetaType sourceMetaType, void *source,
490 Allocate &&allocate, DefaultConstruct &&defaultConstruct)
491{
492 if (const QMetaObject *targetMetaObject = QQmlMetaType::metaObjectForValueType(targetType)) {
493 const auto warn = [&]() {
494 qWarning().noquote()
495 << "Could not find any constructor for value type"
496 << targetMetaObject->className() << "to call with value" << source;
497 };
498
499 if (targetType.canPopulateValueType()) {
500
501 if (const QMetaObject *sourceMetaObject
502 = QQmlMetaType::metaObjectForValueType(sourceMetaType)) {
504 targetMetaObject, defaultConstruct(), sourceMetaObject,
505 [&source](const QMetaObject *sourceMetaObject, int sourceProperty) {
506 return sourceMetaObject->property(sourceProperty).readOnGadget(source);
507 });
508 return true;
509 }
510
511 if (sourceMetaType == QMetaType::fromType<QVariantMap>()) {
513 targetMetaObject, defaultConstruct(),
514 *static_cast<const QVariantMap *>(source));
515 return true;
516 }
517
518 if (sourceMetaType == QMetaType::fromType<QVariantHash>()) {
520 targetMetaObject, defaultConstruct(),
521 *static_cast<const QVariantHash *>(source));
522 return true;
523 }
524
525 if (sourceMetaType.flags() & QMetaType::PointerToQObject) {
527 targetMetaObject, defaultConstruct(),
528 *static_cast<QObject *const *>(source));
529 return true;
530 }
531 }
532
533 if (targetType.canConstructValueType()) {
534 if (fromMatchingType(targetMetaObject, std::forward<Allocate>(allocate),
535 [&](QMetaType, auto callback) {
536 return callback(sourceMetaType, source);
537 })) {
538 return true;
539 }
540 warn();
541 }
542 }
543
544 return false;
545}
546
556 QMetaType targetMetaType, void *target, QMetaType sourceMetaType, void *source)
557{
558 if (sourceMetaType == QMetaType::fromType<QJSValue>()) {
559 const QJSValue *val = static_cast<const QJSValue *>(source);
560 return populateValueType(
562 }
563
564 if (!isConstructibleMetaType(targetMetaType))
565 return false;
566
568 QQmlMetaType::qmlType(targetMetaType), sourceMetaType, source,
569 [targetMetaType, target]() {
570 targetMetaType.destruct(target);
571 return target;
572 }, [target]() {
573 return target;
574 });
575}
576
586 QMetaType targetMetaType, void *target, const QV4::Value &source)
587{
588 if (!isConstructibleMetaType(targetMetaType))
589 return false;
590
592 QQmlMetaType::qmlType(targetMetaType), source, [targetMetaType, target]() {
593 targetMetaType.destruct(target);
594 return target;
595 }, [target]() {
596 return target;
597 });
598}
599
605 const QQmlType &targetType, const QV4::Value &source)
606{
607 void *target = nullptr;
609 targetType, source, [&]() {
610 const QMetaType metaType = targetType.typeId();
611 const ushort align = metaType.alignOf();
612 target = align > __STDCPP_DEFAULT_NEW_ALIGNMENT__
613 ? operator new(metaType.sizeOf(), std::align_val_t(align))
614 : operator new(metaType.sizeOf());
615 return target;
616 }, [&]() {
617 target = targetType.typeId().create();
618 return target;
619 })) {
620 Q_ASSERT(target != nullptr);
621 }
622
623 return target;
624}
625
627 QMetaType targetMetaType, const QMetaObject *targetMetaObject,
628 int ctorIndex, void *ctorArg)
629{
631 fromVerifiedType(targetMetaObject, ctorIndex, ctorArg,
632 [&]() { return createVariantData(targetMetaType, &result); });
633 return result;
634}
635
636static QVariant fromJSValue(const QQmlType &type, const QJSValue &s, QMetaType metaType)
637{
638 if (const auto valueTypeFunction = type.createValueTypeFunction()) {
639 const QVariant result = valueTypeFunction(s);
640 if (result.metaType() == metaType)
641 return result;
642 }
643
644 return QVariant();
645}
646
648{
649 if (!isConstructibleMetaType(metaType))
650 return QVariant();
651 return fromJSValue(QQmlMetaType::qmlType(metaType), s, metaType);
652}
653
655{
656 if (!isConstructibleMetaType(metaType))
657 return QVariant();
658 const QQmlType type = QQmlMetaType::qmlType(metaType);
660 if (mo && type.canConstructValueType()) {
662 if (fromString(mo, s, [&]() { return createVariantData(metaType, &result); }))
663 return result;
664 }
665
666 return fromJSValue(type, s, metaType);
667}
668
670{
671 if (!isConstructibleMetaType(metaType))
672 return QVariant();
673 const QQmlType type = QQmlMetaType::qmlType(metaType);
675 const auto warn = [&]() {
676 qWarning().noquote()
677 << "Could not find any constructor for value type"
678 << mo->className() << "to call with value" << s.toQStringNoThrow();
679 };
680
681 if (type.canPopulateValueType()) {
682 QVariant result = byProperties(mo, metaType, s);
683 if (result.isValid())
684 return result;
685 if (type.canConstructValueType()) {
686 if (fromMatchingType(mo, s, [&]() { return createVariantData(metaType, &result); }))
687 return result;
688 warn();
689 }
690 } else if (type.canConstructValueType()) {
692 if (fromMatchingType(mo, s, [&]() { return createVariantData(metaType, &result); }))
693 return result;
694 warn();
695 }
696 }
697
698 return fromJSValue(type, QJSValuePrivate::fromReturnedValue(s.asReturnedValue()), metaType);
699
700}
701
707{
708 if (!isConstructibleMetaType(metaType))
709 return QVariant();
710 const QQmlType type = QQmlMetaType::qmlType(metaType);
712 const auto warn = [&]() {
713 qWarning().noquote()
714 << "Could not find any constructor for value type"
715 << mo->className() << "to call with value" << s;
716 };
717
718 if (type.canPopulateValueType()) {
719 QVariant result = byProperties(mo, metaType, s);
720 if (result.isValid())
721 return result;
722 if (type.canConstructValueType()) {
723 if (fromMatchingType(mo, s, [&]() { return createVariantData(metaType, &result); }))
724 return result;
725 warn();
726 }
727 } else if (type.canConstructValueType()) {
729 if (fromMatchingType(mo, s, [&]() { return createVariantData(metaType, &result); }))
730 return result;
731 warn();
732 }
733 }
734
735 return QVariant();
736}
737
739QVariant QQmlColorProvider::colorFromString(const QString &, bool *ok) { if (ok) *ok = false; return QVariant(); }
740unsigned QQmlColorProvider::rgbaFromString(const QString &, bool *ok) { if (ok) *ok = false; return 0; }
741QVariant QQmlColorProvider::fromRgbF(double, double, double, double) { return QVariant(); }
742QVariant QQmlColorProvider::fromHslF(double, double, double, double) { return QVariant(); }
743QVariant QQmlColorProvider::fromHsvF(double, double, double, double) { return QVariant(); }
747{
748 return QVariant();
749}
751
753
755{
757 colorProvider = newProvider;
758 return old;
759}
760
762{
763 if (colorProvider == nullptr) {
764 qWarning() << "Warning: QQml_colorProvider: no color provider has been set!";
765 static QQmlColorProvider nullColorProvider;
766 colorProvider = &nullColorProvider;
767 }
768
769 return &colorProvider;
770}
771
773{
774 static QQmlColorProvider **providerPtr = getColorProvider();
775 return *providerPtr;
776}
777
778
781{
782 return new QQmlApplication(parent);
783}
785bool QQmlGuiProvider::openUrlExternally(const QUrl &) { return false; }
786
788{
789 // We don't have any input method code by default
790 QObject *o = new QObject();
791 o->setObjectName(QStringLiteral("No inputMethod available"));
793 return o;
794}
795
797{
798 QObject *o = new QObject();
799 o->setObjectName(QStringLiteral("No styleHints available"));
801 return o;
802}
803
805
806static QQmlGuiProvider *guiProvider = nullptr;
807
808Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *newProvider)
809{
811 guiProvider = newProvider;
812 return old;
813}
814
816{
817 if (guiProvider == nullptr) {
818 static QQmlGuiProvider nullGuiProvider; //Still provides an application with no GUI support
819 guiProvider = &nullGuiProvider;
820 }
821
822 return &guiProvider;
823}
824
826{
827 static QQmlGuiProvider **providerPtr = getGuiProvider();
828 return *providerPtr;
829}
830
831//Docs in qqmlengine.cpp
834{
836 this, SIGNAL(aboutToQuit()));
837 connect(QCoreApplication::instance(), SIGNAL(applicationNameChanged()),
838 this, SIGNAL(nameChanged()));
839 connect(QCoreApplication::instance(), SIGNAL(applicationVersionChanged()),
840 this, SIGNAL(versionChanged()));
841 connect(QCoreApplication::instance(), SIGNAL(organizationNameChanged()),
842 this, SIGNAL(organizationChanged()));
843 connect(QCoreApplication::instance(), SIGNAL(organizationDomainChanged()),
844 this, SIGNAL(domainChanged()));
845}
846
848 : QObject(dd, parent)
849{
851 this, SIGNAL(aboutToQuit()));
852 connect(QCoreApplication::instance(), SIGNAL(applicationNameChanged()),
853 this, SIGNAL(nameChanged()));
854 connect(QCoreApplication::instance(), SIGNAL(applicationVersionChanged()),
855 this, SIGNAL(versionChanged()));
856 connect(QCoreApplication::instance(), SIGNAL(organizationNameChanged()),
857 this, SIGNAL(organizationChanged()));
858 connect(QCoreApplication::instance(), SIGNAL(organizationDomainChanged()),
859 this, SIGNAL(domainChanged()));
860}
861
863{
864 Q_D(QQmlApplication);
865 if (!d->argsInit) {
866 d->argsInit = true;
868 }
869 return d->args;
870}
871
873{
875}
876
878{
880}
881
883{
885}
886
888{
890}
891
893{
895}
896
898{
900}
901
903{
905}
906
908{
910}
911
912static const QQmlData *ddata_for_cast(QObject *object)
913{
914 Q_ASSERT(object);
915 auto ddata = QQmlData::get(object, false);
916 return (ddata && ddata->propertyCache) ? ddata : nullptr;
917}
918
920{
921 Q_ASSERT(mo);
922 if (const QQmlData *ddata = ddata_for_cast(object))
923 return ddata->propertyCache->firstCppMetaObject()->inherits(mo);
924 return object->metaObject()->inherits(mo);
925}
926
928{
929 Q_ASSERT(type.isValid());
930
931 // A non-composite type will always have a metaobject.
932 const QMetaObject *typeMetaObject = type.metaObject();
933 const QQmlPropertyCache::ConstPtr typePropertyCache = typeMetaObject
936
937 if (const QQmlData *ddata = ddata_for_cast(object)) {
938 for (const QQmlPropertyCache *propertyCache = ddata->propertyCache.data(); propertyCache;
939 propertyCache = propertyCache->parent().data()) {
940
941 if (typeMetaObject) {
942 // Prefer the metaobject inheritance mechanism, since it is more accurate.
943 //
944 // Assume the object can be casted to the type. Then, if we have a type metaobject,
945 // the object's property cache inheritance has to contain it. Otherwise we would
946 // end up with diverging metaobject hierarchies if we created the object's
947 // metaobject. This would be a disaster.
948 if (const QMetaObject *objectMetaObject = propertyCache->metaObject())
949 return objectMetaObject->inherits(typeMetaObject);
950 } else {
951 // This is a best effort attempt. There are a number of ways for the
952 // property caches to be unrelated but the types still convertible.
953 // Multiple property caches can hold the same metaobject, for example for
954 // versions of non-composite types.
955 if (propertyCache == typePropertyCache.data())
956 return true;
957 }
958 }
959 }
960
961 // If nothing else works, we have to create the metaobjects.
962
963 return object->metaObject()->inherits(typeMetaObject
964 ? typeMetaObject
965 : (typePropertyCache ? typePropertyCache->createMetaObject() : nullptr));
966}
967
969
970#include "moc_qqmlglobal_p.cpp"
static void setOrganizationDomain(const QString &orgDomain)
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
QString applicationVersion
the version of this application
QString organizationName
the name of the organization that wrote this application
static void setOrganizationName(const QString &orgName)
[11]
static void setApplicationName(const QString &application)
static void setApplicationVersion(const QString &version)
static QStringList arguments()
QString applicationName
the name of this application
QString organizationDomain
the Internet domain of the organization that wrote this application
static void setObjectOwnership(QObject *, ObjectOwnership)
Sets the ownership of object.
@ JavaScriptOwnership
Definition qjsengine.h:275
static QJSValue fromReturnedValue(QV4::ReturnedValue d)
Definition qjsvalue_p.h:189
static QV4::ReturnedValue asReturnedValue(const QJSValue *jsval)
Definition qjsvalue_p.h:249
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
QString arg(Args &&...args) const
\inmodule QtCore
Definition qmetaobject.h:18
int parameterCount() const
QMetaType parameterMetaType(int index) const
\inmodule QtCore
bool writeOnGadget(void *gadget, const QVariant &value) const
QMetaType metaType() const
const char * name() const
Returns this property's name.
\inmodule QtCore
Definition qmetatype.h:320
void destruct(void *data) const
constexpr TypeFlags flags() const
Definition qmetatype.h:2628
constexpr qsizetype sizeOf() const
Definition qmetatype.h:2618
constexpr qsizetype alignOf() const
Definition qmetatype.h:2623
int id(int=0) const
Definition qmetatype.h:454
@ SharedPointerToQObject
Definition qmetatype.h:387
@ WeakPointerToQObject
Definition qmetatype.h:388
@ IsUnsignedEnumeration
Definition qmetatype.h:390
@ PointerToQObject
Definition qmetatype.h:385
@ IsEnumeration
Definition qmetatype.h:386
@ TrackingPointerToQObject
Definition qmetatype.h:389
@ PointerToGadget
Definition qmetatype.h:392
void * create(const void *copy=nullptr) const
constexpr const QMetaObject * metaObject() const
Definition qmetatype.h:2633
constexpr const char * name() const
Definition qmetatype.h:2650
void * construct(void *where, const void *copy=nullptr) const
static bool convert(QMetaType fromType, const void *from, QMetaType toType, void *to)
Converts the object at from from fromType to the preallocated space at to typed toType.
friend class QVariant
Definition qmetatype.h:775
\inmodule QtCore
Definition qobject.h:90
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
QStringList args()
void setDomain(const QString &arg)
void versionChanged()
void setOrganization(const QString &arg)
void domainChanged()
void setVersion(const QString &arg)
void setName(const QString &arg)
void organizationChanged()
QQmlApplication(QObject *parent=nullptr)
virtual QVariant colorFromString(const QString &, bool *)
virtual QVariant lighter(const QVariant &, qreal)
virtual QVariant tint(const QVariant &, const QVariant &)
virtual QVariant fromRgbF(double, double, double, double)
virtual unsigned rgbaFromString(const QString &, bool *)
virtual QVariant fromHsvF(double, double, double, double)
virtual QVariant fromHslF(double, double, double, double)
virtual ~QQmlColorProvider()
virtual QVariant darker(const QVariant &, qreal)
virtual QVariant alpha(const QVariant &, qreal)
static QQmlData * get(QObjectPrivate *priv, bool create)
Definition qqmldata_p.h:199
virtual ~QQmlGuiProvider()
virtual bool openUrlExternally(const QUrl &)
virtual QStringList fontFamilies()
virtual QQmlApplication * application(QObject *parent)
virtual QObject * styleHints()
virtual QString pluginName() const
virtual QObject * inputMethod()
static const QMetaObject * metaObjectForValueType(QMetaType type)
static QQmlPropertyCache::ConstPtr findPropertyCacheInCompositeTypes(QMetaType t)
static QQmlType qmlType(const QString &qualifiedName, QTypeRevision version)
Returns the type (if any) of URI-qualified named qualifiedName and version specified by version_major...
T * data() const
bool canPopulateValueType() const
Definition qqmltype.cpp:543
QMetaType typeId() const
Definition qqmltype.cpp:643
CreateValueTypeFunc createValueTypeFunction() const
Definition qqmltype.cpp:529
bool canConstructValueType() const
Definition qqmltype.cpp:536
static bool populateValueType(QMetaType targetMetaType, void *target, const QV4::Value &source)
static Q_QML_PRIVATE_EXPORT void * heapCreateValueType(const QQmlType &targetType, const QV4::Value &source)
static QVariant constructValueType(QMetaType targetMetaType, const QMetaObject *targetMetaObject, int ctorIndex, void *ctorArg)
static QVariant createValueType(const QJSValue &, QMetaType)
const_iterator constEnd() const noexcept
Definition qset.h:143
const_iterator constFind(const T &value) const
Definition qset.h:161
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5857
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:64
DataPtr & data_ptr()
Definition qvariant.h:703
void * data()
Returns a pointer to the contained object as a generic void* that can be written to.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
Definition qvariant.h:707
QMetaType metaType() const
Definition lalr.h:269
QSet< QString >::iterator it
auto mo
[7]
Combined button and popup list for selecting options.
static QDBusError::ErrorType get(const char *name)
#define qWarning
Definition qlogging.h:162
#define SIGNAL(a)
Definition qobjectdefs.h:52
GLuint GLuint end
GLuint object
[3]
GLenum type
GLenum target
GLsizei GLsizei GLchar * source
GLuint GLfloat * val
GLuint64EXT * result
[6]
GLdouble s
[6]
Definition qopenglext.h:235
GLfloat GLfloat p
[1]
static QQmlGuiProvider ** getGuiProvider(void)
Q_AUTOTEST_EXPORT QQmlGuiProvider * QQml_guiProvider(void)
static void callConstructor(const QMetaObject *targetMetaObject, int i, void *source, void *target)
static QQmlGuiProvider * guiProvider
static void fromVerifiedType(const QMetaObject *targetMetaObject, int ctorIndex, void *source, Allocate &&allocate)
Q_QML_PRIVATE_EXPORT QQmlColorProvider * QQml_setColorProvider(QQmlColorProvider *newProvider)
static void doWriteProperties(const QMetaObject *targetMetaObject, void *target, const QV4::Value &source)
static QVariant fromJSValue(const QQmlType &type, const QJSValue &s, QMetaType metaType)
static bool doWriteProperty(const QMetaProperty &metaProperty, void *target, Get &&get, Convert &&convert)
static bool fromString(const QMetaObject *mo, QString s, Allocate &&allocate)
static QQmlColorProvider * colorProvider
static QVariant byProperties(const QMetaObject *targetMetaObject, QMetaType metaType, const QV4::Value &source)
Q_QML_PRIVATE_EXPORT QQmlGuiProvider * QQml_setGuiProvider(QQmlGuiProvider *newProvider)
Q_AUTOTEST_EXPORT QQmlColorProvider * QQml_colorProvider(void)
static QQmlColorProvider ** getColorProvider(void)
static bool fromMatchingType(const QMetaObject *targetMetaObject, Allocate &&allocate, Retrieve &&retrieve)
bool qmlobject_can_cpp_cast(QObject *object, const QMetaObject *mo)
static const QQmlData * ddata_for_cast(QObject *object)
bool qmlobject_can_qml_cast(QObject *object, const QQmlType &type)
bool createOrConstructValueType(const QQmlType &targetType, const QV4::Value &source, Allocate &&allocate, DefaultConstruct &&defaultConstruct)
static void * createVariantData(QMetaType type, QVariant *variant)
static QT_BEGIN_NAMESPACE bool isConstructibleMetaType(const QMetaType metaType)
static constexpr To convert(const std::array< Mapping, N > &mapping, From Mapping::*from, To Mapping::*to, From value, To defaultValue)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
SSL_CTX int(*) void arg)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
#define Q_AUTOTEST_EXPORT
unsigned short ushort
Definition qtypes.h:28
double qreal
Definition qtypes.h:92
ReturnedValue read(const char *data)
const char property[13]
Definition qwizard.cpp:101
QVariant variant
[1]
\inmodule QtCore
int propertyCount() const
Returns the number of properties in this class, including the number of properties provided by each b...
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
QMetaMethod constructor(int index) const
int static_metacall(Call, int, void **) const
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
int constructorCount() const
Heap::String * newString(const QString &s=QString())
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols=true)
ExecutionEngine * engine
bool isUndefined() const
QString toQStringNoThrow() const
Definition qv4value.cpp:122
static PrivateShared * create(size_t size, size_t align)
Definition qvariant_p.h:55
static constexpr bool canUseInternalSpace(const QtPrivate::QMetaTypeInterface *type)
Definition qvariant.h:102
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent