aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqml.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QtQml: Properly enforce signatures of AOT-compiled functionsUlf Hermann2024-04-261-0/+16
| | | | | | | | | | | | | Pass the metatypes of the contained types rather than the stored types. [ChangeLog][QtQml][Important Behavior Changes] The AOT compiled code for type-annotated JavaScript functions does not let you pass or return values of the wrong type anymore. Fixes: QTBUG-119885 Change-Id: I685d398c0745d32a999a3abd76c622a2c0d6651f Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Improve error message for broken QML_SINGLETONCarl Schwan2024-04-151-2/+2
| | | | | | | | | The current error message doesn't cover the case where the class with the QML_SINGLETON is an abstract class. This will still compile but fail at runtime with an error message not mentioning this case. Change-Id: I134254b252ca3c2250e5f5bc2ac9f9d79a2658fd Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Do not use QQmlEngine from current QML contextUlf Hermann2024-03-211-38/+32
| | | | | | | | | | | | | | | | | We cannot be sure the current context is still alive when a function is called. We may be left with a skeleton context that doesn't have an engine anymore. However, we can always query the QJSEngine given in the AOT context. That one cannot disappear and is generally the right one for capturing properties. Pick-to: 6.7 6.5 6.2 Fixes: QTBUG-123395 Change-Id: I2a6c38baa159fa790f3ba2aba225fdc9cc37001e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Assert on ddata and ddata->propertyCache in doPopulateDeferred()Ulf Hermann2024-03-181-0/+3
| | | | | | | | | | | The caller has to guarantee that the ddata and property cache ar alive at that point. Therefore, make sure that qmlExecuteDeferred() and QtQuickPrivate::beginDeferred() actually guarantee as much. Coverity-Id: 437884 Change-Id: I89bfa5ca47347416d0acd023d073d524363a0635 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Prepare for white allocations during gc (1/9): Write barrier for LookupsFabian Kosmale2024-03-051-4/+4
| | | | | | | | | | | | | | | | | | | | | | | Lookups can (and do) reference HeapItems. This was safe in a non-incremental gc world, as Lookups are always reachable via their containing CompilationUnits, which are part of the root set. However, when using an incremental gc, an already marked Lookup might reference a new heap item, which then becomes otherwise unreachable. This is alleviated by the fact that Lookups generally either refer to something already existing or a freshly allocated string. The latter however is only safe when we can rely on black allocations during gc, and the former is somewhat reckless. Remedy this by employing the WriteBarrier for Lookups. We wrap all HeapItems in a helper class, which -while trivial itself- can't be used for direct assignments. Intead, it employs a set method which ensures that the WriteBarrier is used. Task-number: QTBUG-121910 Change-Id: I6a0ede66ad044076d2e87f134bc95686cb586aee Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Handle non-resettable undefined assignmentUlf Hermann2024-01-251-13/+28
| | | | | | | | | | | | We need to generate an exception if undefined is assigned to a property that can't be reset. We don't want to reject everything that can potentially be undefined. Therefore, we use the QVariant fallback and examine the value for undefined at run time. Pick-to: 6.7 6.6 6.5 6.2 Change-Id: I0a034032f4522f017b452690d93319eb4bfedb1c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Remove QQmlTypeLoader from QQmlImportUlf Hermann2024-01-111-4/+12
| | | | | | | | | The type loader belongs to the engine and we must not store it in engine-independent data structures. We do want the import cache to be stored in the type registry, though (in a separate change). Change-Id: I2828f5098b27bf1fc96852fc2bd160db44b109e7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Allow multiple names for C++-based QML typesUlf Hermann2023-11-151-149/+252
| | | | | | | | | | [ChangeLog][QtQml] You can now have multiple QML_NAMED_ELEMENT macros in the same C++ class to make one C++ type available with more than one QML name. Task-number: QTBUG-101143 Change-Id: I5aeab00a3cd8b3bb11a5a7d5b87ff2e82f57bd7f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Consider the major version when registering singletonsAlexey Edelev2023-11-101-1/+1
| | | | | | | | | | Amends 9225723a317b8c7e805416592b78aca0ed320049 Fixes: QTBUG-117958 Pick-to: 6.6 6.5 Change-Id: Ifbaa30d6f82e37d35d7d3be57fe562dae9d09c10 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Clear the whole lookup in storeNameSloppy()Ulf Hermann2023-11-021-1/+1
| | | | | | | | | | The clear() method was only use by storeNameSloppy() for the temporary lookup. It only cleared part of the lookup. Drop it and do the memset() directly. Pick-to: 6.6 6.5 6.2 Change-Id: Ib31be1d6fba09d2c86f3c4cd64626ab1fd90eb7f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Throw an exception in loadScopeObjectPropertyLookup when qmlScopeObject is nullDmitrii Akshintsev2023-10-241-0/+6
| | | | | | | | | | When object is being destroyed, qmlScopeObject pointer is becoming null (I assume as part of the lookup invalidation?), causing nullptr dereferencing in the subsequent Init lookup stage. This commit prevents it by introducing an "early exit" on the load stage. Fixes: QTBUG-117866 Change-Id: Ifef1a0dd48a952f00f2c0d4d5015ec2f40b7f62a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Don't unnecessarily detour through the CU to look up typesUlf Hermann2023-10-191-6/+0
| | | | | | | | | | | Since we also store partial types as QQmlType now, we can just look them up the regular way. Pick-to: 6.6 6.5 6.2 Fixes: QTBUG-117788 Change-Id: Id3e81853f802419f1121ef5e856c3272a3c977a1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QtQml: Store singleton typename as UTF-8 QByteArrayUlf Hermann2023-08-301-2/+2
| | | | | | | | We rarely want to read it as QString, and we almost always set it from UTF-8 data. Change-Id: I389e9a6de140d8adc09ccc3350685b2d47e03eb8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Key singletons by singleton instance infoUlf Hermann2023-08-301-19/+50
| | | | | | | | | | | | | | | | | | | | We can keep the singleton instance info the same across multiple types created in a single registration call. The result is that we only get one singleton instance per engine, rather than separate ones for each version. If you invoke qmlRegisterSingletonType separately, you still get separate instances, though. [ChangeLog][QtQml][Important Behavior Changes] The QML engine will now refrain from creating separate instances of a singleton type for each version it is registered for if the singleton is registered declaratively (using QML_SINGLETON). The behavior of procedurally registered singletons (using the qmlRegisterSingletonType() family of functions) remains the same: For each registration call, a separate singleton instance is created. Task-number: QTBUG-116432 Change-Id: Ic8a5de0f88ef530670cfd81b192201a8ab49b2f7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Provide infrastructure for writing back lookupsUlf Hermann2023-08-241-43/+180
| | | | | | | | | Some of the "read" lookups we provide need to have a "write back" mode, too. It is just the inverse of the "read" operation. Task-number: QTBUG-116011 Change-Id: Icc5d5bed64a46abff06d052a56cfca9f18836d76 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Allow construction of Date objectsUlf Hermann2023-08-181-7/+26
| | | | | | | | | We map Date to QDateTime and special-case its constructors. Task-number: QTBUG-111624 Change-Id: I0496f853613da3ccee9b6f6c4cf0adffa064f9f8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QmlCompiler: Fix console loggingUlf Hermann2023-08-151-2/+4
| | | | | | | | | | | | | Store a copy of the UTF-8 data for file and function so that we don't run into heap-use-after-free. Set the instruction pointer before calling the log function so that we get a correct line number. Pick-to: 6.6 6.5 Fixes: QTBUG-114655 Change-Id: I38249fe52719ddad620033716ff22b2087ab8382 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Clarify error message for QML type registrationAmanda Hamblin-Trué2023-06-301-2/+3
| | | | | | | Fixes: QTBUG-114966 Change-Id: I3451cf38841cbefe0fa8d7c07ce91da372f8d184 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: Use QQmlType as container for composite types (inline or not)Ulf Hermann2023-06-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This gives us a unified interface to all kinds of QML types at run time and reduces the effort of finding corresponding type attributes. QQmlType is much larger than CompositeMetaTypeIds. Most composite types, however, are initially referenced by URL, and we call typeForUrl anyway. typeForUrl already creates a mostly functional QQmlType; we only need to add the dynamic metatypes. The same type can be retrieved later and associated with the actual CU using the compositeTypes hash. That way, we don't need any extra type. We do, however, incur the cost of creating the QMetaTypePrivate instances when first referencing a type. This could be optimized, like many things in this area, by using thread safe lazy initialization. Now some QQmlTypes implicitly depend on the CUs they were created for. This creates problems if the CUs are removed but the types still persist. Such a situation can arise if you create and delete engines. In order to avoid it, we: 1. Make the compositeTypes hold a strong reference to the CUs 2. When unlinking, avoid dropping the property caches (as those are used to hold the metaobjects) Now, however we got a cyclic reference between the CU and its QQmlType(s). To resolve this, we clear the QQmlTypes on unlinking. Finally, to avoid deletion recursion when clearing the last CUs on destruction of the QQmlMetaTypeData, we move the compilation units out of the way first. All of this still doesn't work if multiple CUs hold the same QQmlType, since compositeTypes can only hold one CU per type and that may be the one that gets removed first. Therefore, we cannot allow such a situation to happen and have to create a new QQmlType if it arises. It can only arise if you have multiple engines loading the same QML components, which should be fairly rare. For inline components, we apply a similar trick: You can either find an inline component by Url, and receive any type that matches, no matter what CU it belongs to. Or you can request an inline component type that belongs to a specific CU. It turns out we don't have to store the containing type of an IC at all. Also, we slightly change the naming of internal components' "class names" since we want to use the inline components' element names for them. Change-Id: I0ef89bd4b0a02cc927aed2525e72f6bff56df626 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Allow anonymous value types to be constructedUlf Hermann2023-06-051-2/+3
| | | | | | | | | | | Only anonymous object types are necessarily uncreatable. You don't need a name in order to construct or populate a value type. Since we can now construct QSize, QRect, and QPoint, the engine will try to construct them from the 'F' variants where applicable. Allow this. Pick-to: 6.5 6.6 Change-Id: I568b93c58d3184d9ac37bf0a542c0e50dd37d8de Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Encode "missing" line number as negated address of stack frameUlf Hermann2023-05-091-2/+14
| | | | | | | | | | | | | | | This way we can identify which entry in a stack frame to amend when processing an exception in generated code. However, negative line numbers are also used to signal the position of "Ret" instructions. Since you cannot throw an exception from a "Ret" instruction, those cannot collide, but we cannot qAbs() the line number anymore when saving it in the stack trace. We have to qAbs() it in all the places where it's read. Pick-to: 6.5 Fixes: QTBUG-112946 Change-Id: I24dc4008fb7eab38e4d24e70211c22e46f1b72a7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Relax shadowing checkUlf Hermann2023-05-021-18/+140
| | | | | | | | | | | | | | | | | If we detect a property or method as potentially shadowed, we don't have to abandon all hope. We can still retrieve it as untyped var. Since there are a number of things we can do with untyped var, this may still be useful. In the same sense, we need to treat function calls as untyped when the function in question can be shadowed. Calling functions with var arguments and return types leads to some more interesting situations in the call frame setup, so we fix that, too. Task-number: QTBUG-112480 Change-Id: I238d1cf04951f390c73e14ed9e299f2aa72b68cb Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Use actual type of enums, rather than intUlf Hermann2023-04-261-8/+72
| | | | | | | | | | Now that the type is available from qmltypes we can just use it. Task-number: QTBUG-112180 Change-Id: I315372da0925f19c209f676226f450863b0d3ea5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QmlCompiler: Implement ConvertThisToObject and basic DTZUlf Hermann2023-04-251-0/+6
| | | | | | | | | | | | | | We know that 'this' is a QObject* since the metatypes stack frame mandates it. Whenever you pass 'this' to anything it's loaded from the special 'This' stack slot which then triggers a DTZ check. A DTZ check is a noop if we can prove that the type is statically known, though. In QmlCompiler, if we have a valid register content, then the register has been set in all code paths that lead to the instruction in question. Fixes: QTBUG-111439 Change-Id: I81d1cd140eea63f85628c3bef3a8f6db0a12096d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Use value type ctorsUlf Hermann2023-03-091-0/+8
| | | | | | | | | | | | | This allows us to do the relevant conversions in a more civilized way, dropping the outputVariantConversion() method. The latter is brittle because you have to manually add it to each instruction, and it uses QMetaType::convert() which is actually not guaranteed to give the same results as a QML type coercion. Task-number: QTBUG-94807 Change-Id: I4d6d05a60beb3b4dfc3da6f0142de25667510904 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Always throw when requesting an enum from an invalid singletonUlf Hermann2023-03-011-1/+6
| | | | | | | | | | | The interpreter does this and so should the enum lookup adapter for generated C++ code. Pick-to: 6.5 6.4 6.2 Fixes: QTBUG-109816 Change-Id: I576480c3ca808743ddc0ceaf2f0bd8a1de776a41 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Make QQmlTypeNotAvailable publicUlf Hermann2023-02-281-2/+7
| | | | | | | | | | | Since we are exposing it in the type registration macros, we need to make it visible to the compiler. Pick-to: 6.5 Fixes: QTBUG-111477 Change-Id: I3dbefd617f00de6e97585d105c612bbc33d0224d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Fortify qmlExecuteDeferred some moreUlf Hermann2023-02-081-8/+14
| | | | | | | | | I don't know how to trigger this, but a recent crash report from the CI shows that we can get there without a valid engine. Pick-to: 6.5 Change-Id: I9f17894da82b8e7eab88181c96dfa8eaf7795523 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Doc: Recommend putting QML files in the same directory as their modulesUlf Hermann2023-02-031-1/+1
| | | | | | | | | Otherwise things quickly get messy. Pick-to: 6.5 Task-number: QTBUG-106929 Change-Id: I9426f3ad3766cad5b133e8ef063696873bb9b7c9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Turn singleton/type mismatch into a run time type errorUlf Hermann2023-01-271-2/+13
| | | | | | | | | | | | | | | | | | | | | | | There are many ways to "hide" the qmldir from the engine at run time, which turns singletons into regular types. While all of this is invalid, we should not assert on it, but rather produce a legible warning. Furthermore, sharpen the importing of extra modules from qrc as implicit imports. We should really only import modules the file in question can ever be part of. Otherwise we needlessly produce the above situation and hide legitimate warning messages. Amends commit 7517c1b3ae9aa92f36b19d74a4b2de5e8531309b. Now we need to teach our tools about the default import paths in the resorurce file system. They cannot guess any type they may find in any resource file anymore. Pick-to: 6.5 Task-number: QTBUG-106929 Change-Id: Ic8c02396d10830a7f461e8a81649bb8c9a1add1f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QML: Output a warning for creatable object types without default ctorUlf Hermann2023-01-231-0/+25
| | | | | | | | Pick-to: 6.5 Fixes: QTBUG-104899 Change-Id: I237ddb68968b26c1ce41051ab3bd3c66fb1712f1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QQmlPrivate: Don't allocate just to parse a numberMarc Mutz2022-12-271-1/+1
| | | | | | | | | | | ... or compare to "true". Use QLatin1StringView::toInt() and qstrcmp() instead. Pick-to: 6.5 Change-Id: I3052895b59c5b8232097bf56255ba328bc6b3e95 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* De-inline QQmlPrivate::revisionClassInfos()Marc Mutz2022-12-271-0/+13
| | | | | | | | | | | | | | It was compiled 1152 times, with the QList::push_back alone contributing a cumulative ~24sec to a 'ninja qtdeclarative'. There's no reason it should be inline, so make it out-of-line. This function was the highest non-QMetaType/non-std contributor in a Clang -ftime-trace build of qtdeclarative. Pick-to: 6.5 Task-number: QTBUG-97601 Change-Id: I143639168f859dc604b902647fe921332bbe49c0 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Fix comparison AOT-lookup and intended type in value typesSemih Yavuz2022-12-051-1/+1
| | | | | | | | | | | | We currently force the lookup metatype to be exactly the same data type with the caller's. As a result, the conversion from enum to integral data type is not recognized. Relax this comparison by using isTypeCompatible helper. Pick-to: 6.4 Fixes: QTBUG-109007 Change-Id: I188dc3e6c1fd7100e9ed5c4ba5d0c90d85d79be4 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Implement console logging methodsUlf Hermann2022-11-231-0/+53
| | | | | | | | | | | We provide semi-private functions in the AOT context for this. Since we cannot know the complete run time type of the potential logging category at compile time, we have to check any first argument that might be one separately. Fixes: QTBUG-107175 Change-Id: I46a8922b1c5c16d2b450b8728d650d31dfd867e3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove signal index mismatch in aot-compiled codeSami Shalayel2022-11-151-1/+2
| | | | | | | | | | | | | | | | | | | | | There are multiple types of signal indexes, one of them belongs to QMetaMethod::signalIndex and another one to QObjectPrivate::signalIndex. Stop mixing them up in aot-compiled code when capturing properties as this leads to weird and hard to debug bugs. Add a smaller version of the drag and drop example as test to make sure that the bug does not appear again, without any visual elements. Fixes: QTBUG-104047 Fixes: QTBUG-104716 Pick-to: 6.4 6.2 Change-Id: I4f64ba237e824ff0ba1624c29ddcf5371d03d69e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port to new Q_UNREACHABLE_RETURN()Marc Mutz2022-10-201-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator to convert sequences of Q_UNREACHABLE() + return into Q_UNREACHABLE_RETURN(), newly added to qtbase. const std::string unr = "unr", val = "val", ret = "ret"; auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(", ifBound(val, cat(node(val)), cat("")), ")"); auto ignoringSwitchCases = [](auto stmt) { return anyOf(stmt, switchCase(subStmt(stmt))); }; makeRule(stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)), nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))), {changeTo(node(unr), cat(makeUnreachableReturn, ";")), // TODO: why is the ; lost w/o this? changeTo(node(ret), cat(""))}, cat("use ", makeUnreachableReturn)); a.k.a qt-use-unreachable-return. subStmt() and nextStmt() are non-standard matchers. There was one false positive, suppressed it with NOLINTNEXTLINE. It's not really a false positiive, it's just that Clang sees the world in one way and if conditonal compilation (#if) differs for other compilers, Clang doesn't know better. This is an artifact of matching two consecutive statements. Change-Id: I3855b2dc8523db1ea860f72ad9818738162495c6 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-071-2/+2
| | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace. Task-number: QTBUG-99313 Change-Id: I601bf70f020f511019ed28731ba53b14b765dbf0 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Allow more options for creating value types from JS objectsUlf Hermann2022-09-241-3/+13
| | | | | | | | | | | | | | | | | | | | We allow value types to be created 1. by calling Q_INVOKABLE constructors 2. by setting their values from properties of a JS object Both have to be opted into by setting a class info. If opted into, these options override the existing methods. When a a type can be created by setting its properties, that implies you can also initialize it using an invokable constructor. However, when given a JS object, the properties method is used. We keep this internal and undocumented for now. As the last try (the create(QJSValue) methods and QJSValue ctors) was not that stellar, let's first wait a bit and see if we're getting it right this time around. Fixes: QTBUG-106480 Change-Id: I767230924afcba032d501846cc3263dad57b7bf0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QML: Optimize QObject method callsUlf Hermann2022-09-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | So far, for each method call we had to allocate a new QObjectMethod as we didn't have any lookup to cache the methods. Introduce a new lookup for that and use it for all QObject methods. Since QObjectMethod contains a pointer to the concrete QObject the method was retrieved from, some more care has to be taken: If we are going to call the method right away, we don't need the object since we always have a thisObject and any further retrieval of the same method will result in a call again. This enables us to cache the method for any instance of the same class. When storing the method elsewhere, though, we need to hold on to the object since you can defer the call or connect a handler to a signal or similar. For such operations we do need the object. We can still optimize a bit by re-using the method cache we build the first time around. Fixes: QTBUG-95628 Change-Id: I5991180c5e0234cdc179c2b78a43dafc9083e525 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Qml: use an enum for the registration struct versionsUlf Hermann2022-09-141-2/+2
| | | | | | | This way we can see more easily what we're checking for. Change-Id: I44b16e8b71ec967b736a4fe5fe0fcbdf28692b90 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Do not call metaTypeFromJS on an objectUlf Hermann2022-09-131-3/+2
| | | | | | | | | This is misleading since the method is static. Change-Id: I921906a06575f263a7619cef01698923d1d5e61f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* QmlCompiler: Allow storeNameSloppy to reset a propertyUlf Hermann2022-07-111-5/+53
| | | | | | | | | We should not convert from undefined on storeNameSloppy. The reset is intentional. Task-number: QTBUG-104508 Change-Id: Iede88fe6331dd173c9e8ea0ec4200df2b8bd30eb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Allow wrapping enums into intUlf Hermann2022-07-071-0/+3
| | | | | | | | | This is what we do internally in the QML engine. Pick-to: 6.4 Fixes: QTBUG-104683 Change-Id: I2f8712cb2cdc56b6c483500627fd8a218edbad81 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Doc: Add \relates command to documented global functionsTopi Reinio2022-07-011-9/+12
| | | | | | | | | | | | | | | qmlRegisterModuleImport() and qmlUnregisterModuleImport() are public, documented global functions but not related to anything. Associate them with QQmlEngine make them appear as related non-members. Same for the related QQmlModuleImportSpecialVersions enum. Drop the QDoc comment tag (/*!) for an internal function. Pick-to: 6.4 6.3 Task-number: QTBUG-99578 Change-Id: I3fa81ff12a2c19e6ed09da6a8398e8d1df141b32 Reviewed-by: Luca Di Sera <luca.disera@qt.io>
* QmlCompiler: Inline translation methodsUlf Hermann2022-06-241-12/+32
| | | | | | | | | We hardcode them into QQmlJSTypePropagator and QQmlJSCodegenerator for now. This is OK for builtins. Task-number: QTBUG-101387 Change-Id: Ifab46083b3a782f009859ce969c283d5bb2b4e8b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Qml: Allow major version of module to be zeroAlexandru Croitor2022-06-181-1/+1
| | | | | | | | | | | | | If there is no QML.AddedInVersion then the component should be available from version X.0, with X being the current version of the module. Amends 464abaec05e0aa0ab699243412c50a5d5ac30742 Pick-to: 6.3 6.4 Fixes: QTBUG-104373 Change-Id: If30b66df384fe815c41d2a0b5ca7b034b9955956 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Use SPDX license identifiersLucie Gérard2022-06-111-38/+2
| | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Pick-to: 6.4 Task-number: QTBUG-67283 Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Support querying indirect extensions for a given objectAndrei Golubev2022-05-121-2/+7
| | | | | | | | | | | | | | Introduce a private version of qmlExtendedObject() that returns an index-based extension (where 0 represents an extension on the leaf type and N represents a (N - 1)th base type's extension) Teach QQmlProxyMetaObject to distinguish different extension proxies. Its custom metaCall can now query up to 128 extensions (should be enough for the user needs) Change-Id: I5520a1e84501f1f9fe6a8e77d8269009a12c255c Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QML: In captureLookup(), return false if it failsUlf Hermann2022-03-251-2/+1
| | | | | | | | | | | | | Otherwise the AOT-compiled code will assume the capture succeeded and fail to get notified when the value changes. This went unnoticed because it only applies to direct mode, the tests for which live in a separate repository. Fixes: QTBUG-102022 Change-Id: I23d94ccbef5b00c4c6837c88970a4e40b05a912a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit d52e1d609516d0573bea1acf2d73d811ff25f0e9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>