aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
Commit message (Collapse)AuthorAgeFilesLines
...
* tst_qqmlmetatype: Improve error messages on mismatchUlf Hermann2024-04-231-2/+10
| | | | | | | | We want to know what types were involved. Change-Id: I456b35e6688b01c14baa681fe62a461a5f082f5d Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlcachegen: Improve warnings for missing return type annotationsOlivier De Cannière2024-04-237-5/+71
| | | | | | | Fixes: QTBUG-124220 Pick-to: 6.7 Change-Id: Ic31b90b0408d855a45e17647ab659fbbc6e17633 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmltc: Move qlmtc_build_failures to tst_qmltc_qprocessLuca Di Sera2024-04-233-0/+22
| | | | | | | | | | | | | | | | | | | | | | | `qmltc_build_failures` uses the available CMake infrastructure to test for expected build-level failures from a `qmltc` compilation. This allows tracking failures over certain constructs that `qmltc` should not support, but has an high amount of friction when extended, as each "test case" needs to be its own whole project, and doesn't provide an error-level granularity for the failures, so that the success of a "test case" might depend on a failure that is different from the intended one. `tst_qmltc_qprocess` has the infrastructure required to run failing `qmltc` builds in a leaner way, provides an easier extension story, based on the general and well-known testlib-based structure and allows to have tests with an error-level granularity. Hence, remove `qmltc_build_failures` and move the existing "test case" to `tst_qmltc_qprocess`. Change-Id: Ib11227c0da1f6336e6537bea76011ccc0090039f Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmltc: Test fail for unbound outside required property in componentLuca Di Sera2024-04-234-0/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `qmltc` should fail when it processes a QML file that defines a component that has unbound inner-level required properties imported from an outside type. For example: ``` Item { Component { id: mycomp Item { TypeWithRequiredProperty {} } } } ``` Where `TypeWithRequiredProperty` defines at least one required property. To parse a QML file, `qmltc` uses `QQmlJSImportVisitor`, which will produce an error on encountering such a case. `qmltc` will in turn propagate the error and fail itself, thus acting properly. A new test was added to keep track of the behavior and ensure that `qmltc` rejects a file when this erroneous form is encountered. Fixes: QTBUG-120698 Change-Id: I7f4dab3501c792b2b2a3d97b20ad416748a3d4a9 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmltc: Test failure for unbound required properties in componentLuca Di Sera2024-04-233-0/+30
| | | | | | | | | | | | | | | | | | | | `qmltc` should fail when it processes a QML file that defines a component that has unbound inner-level required properties, similarly to how it should generally fail when an unbound inner-level required property is present, as those are not settable at a later phase. To parse a QML file, `qmltc` uses `QQmlJSImportVisitor`, which will produce an error on encountering such a case. `qmltc` will in turn propagate the error and fail itself, thus acting properly. A new test was added to keep track of the behavior and ensure that `qmltc` rejects a file when this erroneous form is encountered. Task-number: QTBUG-120698 Change-Id: Iadb9648ea09951a1741679c9c27abe014876656b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmltc: Test failure for unbound required property in inline componentLuca Di Sera2024-04-233-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `qmltc` should fail when it processes a QML file that instances an inline component that has some top-level required properties without setting them when creating the instance. For example: ``` import QtQuick Item { component IC: Item { required property int i } IC { // i needs to be set here as it cannot be set later } } ``` To parse a QML file, `qmltc` uses `QQmlJSImportVisitor`, which will produce an error on encountering such a case. `qmltc` will in turn propagate the error and fail itself, thus acting properly. A new test was added to keep track of the behavior and ensure that `qmltc` rejects a file when this erroneous form is encountered. Task-number: QTBUG-120698 Change-Id: I1a1b7a3d55f3ba5dde7d04b014b7d6a9b53a546d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Fix some type conversion edge casesUlf Hermann2024-04-232-0/+27
| | | | | | | | | | | | If the type conversion code fails to convert an argument, we still need to make sure the argument has a definite value. Otherwise we may trigger undefined behavior somewhere down the line. Furthermore, we want to look at the precise type when converting list properties. Otherwise we get a list property without any methods back when converting. Pick-to: 6.7 6.5 6.2 Change-Id: I012c0360ef1578c768362d5a4648252d3e6803d8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* V4: Handle all array-like containers when converting to QJsonArrayOlivier De Cannière2024-04-224-0/+88
| | | | | | | | | | | | | | | | Commit b9bfdea0e2c6721d2306af0ecc44f88da9988957 removed specialized code for QVariantList conversions by relying on sequences instead. Some checks for sequences and other array-like containers were missed. Add those and perform all calls to QJsonObject::toJsonArray through a common QV4::Object interface. Amends b9bfdea0e2c6721d2306af0ecc44f88da9988957 Pick-to: 6.7 Fixes: QTBUG-123993 Change-Id: Ia671d556af4f2b4d44f652fa93182977d88621f2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlsc: Support Math static propertiesLuca Di Sera2024-04-184-0/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The javascript Math object presents some static properties that allow access to some general mathematical constants. Currently, `qmlsc` will refuse to generate optimized code for those properties when used in a binding, for example given: ``` import QtQuick Window { width: 200 * Math.PI } ``` `qmlsc` will report a warning and will not generate code for the "width" binding. To allow `qmlsc` to generate optimized code for such cases, the handling of `Math` related properties lookups is now specialized. `QQmlJSTypePropagator::propagatePropertyLookup`, which is called when dealing with an access such as `Math.PI`, was modified to consider the result type a "double" when dealing with properties on the `Math` object. `QQmlJSCodeGenerator::generate_GetLookupHelper`, which generates the code that provides a value for the property access, was modified to special case lookups on the `Math` object. If a property is being looked up on the `Math` object, `qmlsc` will now generate a direct assignment for the output variable to a constant value that is suitable for the accessed property. A test was added to ensure that the snippet from the bug-report now compiles without warnings. A test was added to ensure that the properties from the Math global object have an approximately correct value. Fixes: QTBUG-113150 Change-Id: I8903794fc8ce2b55532a4706e1bda07a7b73f311 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: enable environment variables like QML_IMPORT_PATH via -ESami Shalayel2024-04-181-5/+70
| | | | | | | | | | | Add a -E commandline option for qmllint to enable using environment variables. For now, this only allows using QML_IMPORT_PATH and QML2_IMPORT_PATH to pass import paths to qmllint. Task-number: QTBUG-114969 Change-Id: Ie6baf9c8035703a456ba1e7e575ba424f89d287a Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlJS: Store method's source location and expose it in QQmlSAOlivier De Cannière2024-04-172-0/+46
| | | | | | | | | This is useful for tooling like Axivion and can help with better error messages. Change-Id: Ic63afd2eeb4ee3627d05303c2518fa90282fb7ab Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* qmllint: do not ignore command line options with --ignore-settingsSami Shalayel2024-04-174-0/+24
| | | | | | | | | | | | | | | Remove a misplaced pair of braces that made --ignore-settings ignore the parsing of command line options like "-I", "-E" and "--bare". Do not populate the settings from a settings file when --ignore-settings is set to make QQmlToolingSettings::isSet() always return false. Discovered while working on QTBUG-114969. Pick-to: 6.7 6.6 6.5 Task-number: QTBUG-114969 Change-Id: Ia8719b33af4a2ebdcb2b81194e0c028164775327 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* Fix adding columns to TreeViewAntti Määttä2024-04-172-0/+29
| | | | | | | | | Handle the column related signals in the qqmltreemodeltotablemodel. Fixes: QTBUG-94100 Pic-to: 6.7 6.6 6.5 Change-Id: I4a1d4ee4e2f927e7798211f314a1356721748c92 Reviewed-by: Antti Määttä <antti.maatta@qt.io>
* QQmlComponent::loadFromModule: Improve error handlingFabian Kosmale2024-04-171-0/+8
| | | | | | | | | | | | | | | | | | | | | Most importantly, fix the (attempted) loading of a non-existent inline component: As soon as we have the compilation unit, we can simply check whether the inline component exists via its name. This avoids an assert down the line in beginCreate which assumes that at this point the inlineComponentName has been properly vetted. This also allows us to create a better error message, and to catch the easy mistake of passing a file name instead of a type name to createComponent. Moreover, ensure that we do not claim that the inline component is ready when only the outer component has been loaded – a direct connection to the changed signals followed by a call to create would otherwise yield surprising results. Fixes: QTBUG-124225 Pick-to: 6.7 Change-Id: I6b1860f594a3060653e732b9570cc3bbff0c34a9 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* DelegateChooser: React to changes of choice property (via QAIM)Fabian Kosmale2024-04-162-0/+115
| | | | | | | | | | | | | | | | | | | | Detect when a QAIM changes the value of the role affecting the choice made by DelegateChooser and tell the view to recreate the delegate if necessary. For performance reasons, we don't want to track changes for non-QAIM based models [1]; document this remaining limitation. [1]: We don't have a convenient place where we could detect both the "role" change and the affected index (which means that we would need to invalidate everything, and possibly way too often.). It might be possible to refactor the code to allow for this, too, but that would robably be a larger change, and not suitable for picking it back. Pick-to: 6.7 Fixes: QTBUG-75887 Change-Id: Ic91dc436e53b4280debf2698c76f2ead4bdf15d6 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Improve error message for broken QML_SINGLETONCarl Schwan2024-04-151-21/+21
| | | | | | | | | 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>
* qmltyperegistrar: Improve readability and performanceUlf Hermann2024-04-132-12/+12
| | | | | | | | | | Instead of working on opaque Cbor objects, we can use structs and classes with named members. This also improves performance as we don't have to repeatedly query the Cbor data structures. Task-number: QTBUG-101143 Change-Id: Ifd889323f0fd723a735be3e7d70230e61039b301 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Add a wrapper builtin for QQmlV4Function*Ulf Hermann2024-04-125-7/+7
| | | | | | | | | This way qmltyperegistrar can recognize it and refrain from warning about it. Task-number: QTBUG-101143 Change-Id: I598140e7e90dbd3e27a78c26eff3d46f0fd3e989 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Allow coercion of lists to stringsUlf Hermann2024-04-113-0/+51
| | | | | | | | | | We have to allow two different forms of coercion. When printing directly through console.log etc, we add a pair of square brackets around the string. Fixes: QTBUG-119482 Change-Id: I03177e5905b41f5f0b5aaa867b18379eb9c7a243 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Correctly mark side effects for list operationsUlf Hermann2024-04-113-0/+30
| | | | | | | | | | | The contents of a QQmlListProperty are mutable even if the property is not. This is because QQmlListProperty is only a view on a different container. Pick-to: 6.7 Fixes: QTBUG-123196 Change-Id: Id6309b1e1ddc219bf35e8d9888b8415dcc0f9d43 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlformat: Preserve up to 1 empty line between statementsLuca Di Sera2024-04-118-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When `qmlformat` processes a `ScriptExpression` such as the `onClicked` body in the following snippet: ``` import QtQuick MouseArea { onClicked: { console.log("start"); console.log("end"); } } ``` It will remove every empty lines between statements. For example, in the above snippet, the two log statements will be on successive lines in the formatted output, removing the empty line in-between them in the original version. `qmlformat` will now, instead, allow up to 1 empty line to be preserved between statements, if at least one empty line is present in the original version. The formatting for `StatementList`s in `ScriptExpression`s is handled by the relevant overload of `ScriptFormatter::visit`. The code relative to inserting newlines in-between statements in the list was modified to take into account the possible presence of additional empty lines in between the statements, outputting an adequate amount of newlines to preserve up to 1 empty line. The utility method `ScriptFormatter::newLine`, which is used to output a single newline character, was modified to take a parameter representing the amount of newlines that should be added, allowing multiple newline characters to be written by a single call. A non-exhaustive test-case for the new behavior was added to track it. Certain pre-existing snapshot test-cases were modified to be in line with the new output of `qmlformat`. Fixes: QTBUG-123864 Change-Id: I552d1f7ce2c035b9087cb60a3b6e3480c5ae969a Reviewed-by: Dmitrii Akshintsev <dmitrii.akshintsev@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Correct license for test filesLucie Gérard2024-04-112-2/+2
| | | | | | | | | | | | | According to QUIP-18 [1], all test files should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Task-number: QTBUG-121787 Pick-to: 6.7 Change-Id: Ib1dea3bf095aeb06e33a64db61a8c01219d12345 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmltc: Enforce basic required propertiesLuca Di Sera2024-04-095-3/+191
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Types in QML can expose "required" properties. A required property is a property that should be initialized when an instance of the type is built. Instantiating a type without initializing its required properties is an hard error. Currently, `qmltc` generated types do not respect the semantic of "required" properties. Instead, `qmltc` will generally default-initialize a required property without notifying the user of the error. `qmtlc`, so as to respect the semantic of required properties, will now require the user to pass an initial value for all required properties at construction time. To do so, `qmltc` will now generate a new inner record, `RequiredPropertiesBundle`, for each compiled top-level type, that contains the required amount of data to initialize each top-level required property that is reachable from the compiled type. An instance of `RequiredPropertiesBundle` will be required, as long as the type presents at least one required property, in the user-facing constructor for the generated type. The information stored in the instance will later be used to provide an initial value for each required property during the construction of the component. An intermediate representation for `RequiredPropertiesBundle` was added to "qmltcoutputir.h". `QmltcCodeWriter`, the component responsible for writing the final C++ code, was modified to take into consideration the presence, or lack thereof, of a `RequiredPropertiesBundle` and output the necessary code when required. The code taking care of populating the various IRs was modified to populate a `RequiredPropertiesBundle` for top-level components as necessary. Similarly, the code populating the parameters of the user-facing constructor was modified to require an instance of `RequiredPropertiesBundle` when necessary. The code that populates the body of the user-facing constructor for top-level types was modified to make use of the parameter by tying into the existing structure for setting initial values. `qmltc` uses a user-provided callback to allow the user to set the initial values for properties when constructing a top-level component. The body of the user-facing constructor was modified to compose the user-provided callback with a callable that sets the initial values for top-level required properties based on the bundle of data in the new `RequiredPropertiesBundle` instance. The code that populates the body of the user-facing constructor was moved into its own free-function, `compileRootExternalConstructorBody`, to be slightly more explicit about the structure of the code. A new test was provided to evaluate, some basic cases for the new behavior. Some pre-existing tests, which made use of required properties, were modified to comply with the new generated API. The documentation for `qmltc` was modified with a note about the new behavior. Task-number: QTBUG-120698 Change-Id: I1e916dcd91ae976629dad8adc7eacc6390bce7e9 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* ListModel: Treat QV4::Sequence and QV4::QmlListWrapper like arraysUlf Hermann2024-04-082-0/+187
| | | | | | | | Pick-to: 6.7 Fixes: QTBUG-124084 Change-Id: I99f900b71d71f33f807f5f69829bb9ef760b40c8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Handle scripts as type lookups on GetLookupUlf Hermann2024-04-054-0/+23
| | | | | | | | | | | This can happen if you lookup a script from a type namespace. The type lookup already has facilities for handling (or rather rejecting) it. Pick-to: 6.7 6.5 Fixes: QTBUG-123050 Change-Id: I092b1d2f47edc152b4f3967b4eaf4620a81ce5ef Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* QtQml: Add option to disambiguate resources for qmldir filesUlf Hermann2024-04-051-0/+3
| | | | | | | | | | | | If you have multiple modules with the same target path in the same directory, they will otherwise overwrite each others' .qrc files. This is not a very sane thing to do in general, but it happens in our tests. Task-number: QTBUG-124145 Change-Id: Ice5368d8b61907f610ad7e6e7370b43c2056c2fb Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QtQml: Resolve generalized group properties during alias resolutionUlf Hermann2024-04-053-0/+151
| | | | | | | | | This way we can know the scope in which to search for the IDs. Pick-to: 6.7 6.5 Fixes: QTBUG-123865 Change-Id: I1dff9bdc69e3edaa80d85c757e3bb2b24e174cd0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* tst_qmltyperegistrar: Add missing autotool setup for plugin targetFabian Kosmale2024-04-051-0/+1
| | | | | | | | | | | | Otherwise, toplevel builds might fail if moc hasn't been build yet. Amends f080d0309d4c1d0d8a96dabe832162c5f41b881f. Pick-to: 6.7 6.5 Change-Id: Ifcdbc05a839f253d2aed192f38826e631bbf09c3 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> Reviewed-by: Matthias Rauter <matthias.rauter@qt.io> Reviewed-by: Orkun Tokdemir <orkun.tokdemir@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: do not construct well known valuetypes from string (part 1)Sami Shalayel2024-04-056-3/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a warning when well-known QML_STRUCTURED_VALUE's type are constructed from strings in bindings, with a fix-it to automatically generate the QML_STRUCTURED_VALUE way of constructing value types. Do not provide a fix-it in the case that a value type is constructed from an invalid string, like "50x70" instead of "50,70" for a QPointF, for example. Previously, qmlcachegen was compiling some of the string assignments for structured types like points, and some not, like vector2d. In the latter case, it printed the generic "Cannot assign literal of type ..." from the qmlIncompatible category. This commit only handles point, size and rect. A later commit will take care of the quick/gui types matrix4x4, vectorNd and quaternion. Now that the methods are all accessible from one point and consistently reused, implement qqmljsvaluetypefromstringcheck that checks if a given type should be constructed from a stringliteral, and generates a suggestion using the new way of constructing structured value types if it can. This is implemented into a separate header because it might be needed for multiple checks. Currently, it is only needed for the stringliteral "binding" check, but it will also be needed for stringliteral "assignment" checks, where you warn about `myPoint ="1,2"`, for example (see QTBUG-118547). To avoid code-duplication in the quicklintplugin, extract the code also needed for the qquickliteralbindingcheck into a separate base class LiteralBindingCheckBase, such that qquickliteralbindingcheck, in a later commit, may just extend LiteralBindingCheckBase using its isValueTypeFromStringConstruction override. Task-number: QTBUG-118323 Fixes: QTBUG-118546 Change-Id: I8572798d94593b1044cdb49116c8468f998dbbd7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: do not complain about JS typesSami Shalayel2024-04-053-0/+17
| | | | | | | | | | | Do not complain about types coming from .js files, as we cannot reasonably verify them. Fixes: QTBUG-120551 Pick-to: 6.7 6.5 Change-Id: Id74b1869f341c29baedddf88e0f9c19654de38e7 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QtQml: Discard events on engine shutdown rather than processing themUlf Hermann2024-04-052-0/+46
| | | | | | | | | | | | | | | This also deletes them, and releases any references they still hold. However, it doesn't give us headaches about delivering events to half-dead objects. Amends commit ebceda0cad6d86f6d6fe5efbf85a3b06fb4222b0 Pick-to: 6.7 6.5 Fixes: QTBUG-122925 Change-Id: I4509d23b2233965b8be8e4069ae61b0b82daf1e5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Varanka <sami.varanka@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* V4: Don't call methods on nullptrUlf Hermann2024-04-051-0/+21
| | | | | | | | | | The root node of a sparse array can be null. Pick-to: 6.7 6.5 6.2 5.15 Fixes: QTBUG-123596 Change-Id: I5ea7fd73aeec460082d0cf19c7fc8a01993ed1f9 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* tst_qqmlprofilerservice: Wait up to 30s for first frame of a windowUlf Hermann2024-04-041-1/+1
| | | | | | | | | Opening windows can be extremely slow on overloaded CI machines. Pick-to: 6.7 6.5 Change-Id: If65035071b2b2dbace7e8ecb7e5eb92166dc0f9f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Fix heap-buffer-overflow in ESTable::removeOliver Dawes2024-04-043-0/+65
| | | | | | | | | | | Fixes a heap-buffer-overflow issue in ESTable::remove due to an off by one error in the count provided to memmove calls. Task-number: QTBUG-123999 Pick-to: 6.7 6.5 6.2 5.15 Change-Id: I4ee0fbc16ba8936ea921e5f1d1bb267dae0b1d5f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Tests: check that QFile::open succeedsGiuseppe D'Angelo2024-04-0410-14/+25
| | | | | | | | | | Wrap it in QVERIFY if possible. If not possible (e.g. a function that returns non-void, or not an autotest function) use qFatal to abort the test. Change-Id: Ie255024d29507e928a94e67d9af1cd436df4f1df Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Generate qmldir files for extra directories with QML filesUlf Hermann2024-04-035-5/+87
| | | | | | | | | | | | | | | | Those qmldir files contain only a prefer directive for the canonical resource location of the module. This way, any time another component from the implicit import is requested, it will not be located in the extra directory (where it probably doesn't exist), but instead in the canonical location. Since people may have manually written qmldir files with different content in those places, or worse, relied on the other components to be inaccessible, we need a new policy to opt into this. Fixes: QTBUG-111763 Change-Id: If236feb7dd7c8d704b813ea56482ff758799d0a7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Resolve preferred paths before setQmldirContentUlf Hermann2024-04-036-1/+32
| | | | | | | | | | We want the content from the preferred qmldir to be used. This way we can omit all the details from the original qmldir. Task-number: QTBUG-111763 Change-Id: I3a0b3db0207e919c962c98d79f9f200aaf3cad96 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Follow prefer directives in QML toolingUlf Hermann2024-04-038-0/+45
| | | | | | | | | | | | | Since we now have all the resource file mappings we can figure out if the module being preferred is still the same as the one we are currently parsing. If not, we can switch. This way we can introduce redirection from subdirectories to parent directories. Task-number: QTBUG-111763 Change-Id: I21045f27533716511f7252d6e4c983300042e1b6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQmlJSImportVisitor mark required aliases as required in their scopeLuca Di Sera2024-04-022-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When `QQmlJSImportVisitor` visits a program, it marks properties as required in their scope when it encounters them or it encounters a `required` statement. For aliases, an additional step is performed at the end of a visit, when the aliases are resolved. After an alias is resolved to a target property, is "requiredness", is set based on the required of the target property in its scope. Due to the specific implementation, the alias will be set to required in its scope if the target property is required in its scope and will be set to be non-required otherwise, independently of its previous required state. When we have an alias that is itself required pointing to a property that isn't required, for example: ``` Item { id: self property int foo property alias alias: self.foo required alias } ``` The alias will always be marked as not required, as it always inherits the required state of the target property, losing the required status that was applied by the "required" statement. To respect "required" statements in relation to aliases, `QQmlJSImportVisitor::resolveAliasesAndIds` will now inherit the "requiredness" of the target property only when the alias is not already marked as required in its scope. Fixes: QTBUG-123837 Change-Id: I7b0f6958287625f3f3a5d736d4c45a3e050d4502 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add unit test for QML_ELEMENT as Q_GADGET in a namespaceAndre Klitzing2024-03-301-0/+10
| | | | | | | | | It was fixed by fa081b89f0bf8813e11d00436ab0dc9fb5efb378. Task-number: QTBUG-123592 Pick-to: 6.7 6.5 Change-Id: I6eb60f65efe608f99b92ccd595b19eac5b78d710 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlListWrapper: Don't use QQmlListReference for virtualGetLength()Ulf Hermann2024-03-282-0/+20
| | | | | | | | | | | We cannot use QQmlListReference on detached list properties. Also, it's wasteful. Pick-to: 6.7 Fixes: QTBUG-118076 Change-Id: I754f19ed8c3f6eae1b3613f6866f3cf792cee8cf Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Fix namespace in namespace detection of a foreign typeAndre Klitzing2024-03-271-0/+11
| | | | | | | | | | Add full qualified name to QML_FOREIGN, otherwise it won't detect a namespace in a namespace. Task-number: QTBUG-123535 Pick-to: 6.7 6.5 Change-Id: I679edc2566739ee52bf531ecec64789350fcdd11 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Fix wrong generation of Q_NAMESPACESAndre Klitzing2024-03-273-0/+38
| | | | | | | | | | Generate Q_NAMESPACE if foreign type is a namespace. Add compilation test for this only. Fixes: QTBUG-123535 Pick-to: 6.7 6.5 Change-Id: Iacce6681a3fba468c1a9646630c871e2553d56bd Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Engine: Handle grouped property bindings of non-registered typesFabian Kosmale2024-03-276-1/+122
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is possible to expose a type to QML which exposes a QObject (derived) property, which then gets used to create a grouped binding. The type of the property might not have been registered in QML, or it might be part of a base class which exposes the type already in another module. If that module is not imported (or does not exist at all), the property creator would so far bail out. Simply skipping the check would lead to crashes further down, as we also lack the property cache needed during object creation. However, in Qt 6, we can lift this restriction: We can retrieve the property's metatype, and from there we can fetch the metaobject. Once we have the metaobject, we can on-demand create a property-cache for it, and use that later in the object creator. One restriction we add is that the type must not have a dynamic meta-object, given that those don't lend themselves to usable propety caches (given their dynamic nature.) The early check in the property validator is adjusted accordingly. Add a quick test to verify that gadgets continue to work as before. As a drive-by, convert a few repeated QString::arg calls to a single call of the variadic overload. Task-number: QTBUG-122321 Pick-to: 6.7 Change-Id: I860af981250a70f541794b57db3764415ea172f0 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* tst_qmllint: Do not require a GUIFabian Kosmale2024-03-261-1/+1
| | | | | | | | QTEST_MAIN instantiates QApplication; but our tests only need QCoreApplication. Change-Id: Ieed2157cfa2e7d2c96444248f951cc88e46486b8 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlCompiler: Fix code for object literal generationUlf Hermann2024-03-262-0/+9
| | | | | | | | | | | | | | We have to use the arguments as base for the run time calculated members, not the argument count. Amends commit f839171eefbba670536262fa3b847d24bfdc627b. Pick-to: 6.7 Fixes: QTBUG-123613 Change-Id: I3ddc8bc459618bd9a9436d3616c444bf218463a3 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Adapt to privatising of QPropertyBinding's ref countUlf Hermann2024-03-251-1/+1
| | | | | | | | | | | Change-Id: I95474784c1eb8c8d8f5dafd33dcc32f532bffe47 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Liang Qi <liang.qi@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io> Reviewed-by: Matthias Rauter <matthias.rauter@qt.io> Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
* qmltyperegistrar: Clarify confusion about isCreatableUlf Hermann2024-03-222-0/+31
| | | | | | | | | | | | | | For value types isCreatable means that the type is constructible. For object types it means that it can be instantiated as a QML element. Since the default is "true" in both cases, this is somewhat confusing. Always generate an explicit isCreatable attribute for all types to clarify this. Also, fix the generation of isStructured as a drive-by. Fixes: QTBUG-123089 Change-Id: I9d33d2448facc369f524ba8c68a2403ccc4c6aa5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Correct license for test filesLucie Gérard2024-03-221-1/+1
| | | | | | | | | | | | According to QUIP-18 [1], all test files should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Task-number: QTBUG-121787 Pick-to: 6.7 6.7.0 Change-Id: Ib686439e6a61fd3169948dd8a2b51f8fe1ca21b1 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* qmltc: Support setting initial values for reference list propertiesLuca Di Sera2024-03-214-4/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When `qmltc` compiles a QML type to C++, it generates a proxy object for the compiled type, `PropertyInitializer`, that knowns how to set the top-level property of the component. A user can then pass a call-back to the constructor for the compiled type and use an instance of the generated `PropertyInitializer` to set the initial values for the top-level properties of the component. Currently, the generated `PropertyInitializer` would refuse to generate a setter for properties whose type is a list of object types, impeding the user from being able to set the initial values for properties of this kind. To allow setting the initial values for properties whose type is a list of object types, `qmltc` will generate a setter for those properties when generating the `PropertyInitializer` class for a type. The free function `compilePropertyInitializer` in "qmltccompiler.cpp", that is responsible for generating the `PropertyInitializer` class for a type, was modified to produce a setter for properties whose type is a list of object types. The test that verifies the initial values behavior was modified to have representative cases for the modified feature. Fixes: QTBUG-120700 Change-Id: I4a023263ca3dfa3c77c11d1522b8be47b7958109 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>