Hi Matthew,
-- QtLocation --
The linter is unable to resolve types in QtLocation. Adding the
following dependencies to qml/QtLocation/qmldir resolved the problem:
depends QtQuick
depends QtPositioning
Thanks for catching this. See
https://codereview.qt-project.org/c/qt/qtlocation/+/500504 for a fix.
-- Enums in gadgets --
The linter is unable to resolve enums defined in gadgets (Type not found
in namespace [unresolved-type]). The class definition looks like this:
struct MyType
{
Q_GADGET
QML_ELEMENT
This doesn't work. MyType is a value type and value types must have
lower case names. QML_ELEMENT exposes it under an upper case name here
("MyType"). Even if you were to give it a lower case name using
QML_NAMED_ELEMENT you could still not access its enums, though, because
types with lower case names are (by default) not addressable in QML.
So, what you want to do is expose MyType as a namespace instead:
namespace MyTypeNamespace {
Q_NAMESPACE
QML_FOREIGN_NAMESPACE(MyType)
QML_NAMED_ELEMENT(MyType)
}
The runtime reference works. Following the instructions here
https://doc.qt.io/qt-6/qtqml-cppintegration-overview.html, even with the
QML_UNCREATABLE macro, the type could still not be resolved. Looking at
the qmltypes file, if the 'accessSemantics' for the type is changed to
'reference' from 'value' the linter works. Is this a problem with
linter, or possibly with the macro annotations of the type?
You cannot have reference semantics on a value type. A type with
reference semantics (aka an "object type") needs to be derived from
QObject and have a Q_OBJECT macro. The engine plays somewhat loose with
that and allows you to still access enums from such broken types. We
should amend the documentation to warn about this problem and also
generate a run time warning from the engine.
-- 'as' operator --
The 'as' operator has been used to deal with the 'missing-property'
warning in this type of pattern in QML
Loader {
id: loader
sourceComponent: Dialog { ... }
}
... {
(loader.item as Dialog).open()
}
This silences the linter, but at runtime there is an error, in this case
when the 'open()' function is called: 'TypeError: true is not a function'.
What is the status of the 'as' operator? It doesn't appear to be
documented. Can it be used, or does it have known short-comings?
This should work. Type assertions (aka "as cast") are documented in
https://doc.qt.io/qt-6/qtqml-javascript-hostenvironment.html . What kind
of object does the loader produce here? Can you please open a bug report
with a minimal example?
Please also note the type registration is done manually, not with the
code generated by qmltyperegistrar. Any pointers would be appreciated.
My pointer about that is rather simple: Do use qmltyperegistrar and have
it generate consistent type registrations. That will probably fix some
of your problems.
best regards,
Ulf Hermann
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest