Cross-platform software libraries and APIs
Qt Creator IDE and productivity tools
UI Design tool for UI composition
for Qt projects
Digital advertising for UI apps
Usage intelligence for embedded devices
GUI test automation
Code coverage analysis
Test results management and analysis
Software static code analysis
Software architecture verification
The latest version of Qt.
Make the most of Qt tools, with options for commercial licensing, subscriptions, or open-source.
Explore Qt features, the Framework essentials, modules, tools & add-ons.
The project offers PySide6 - the official Python bindings that enhance Python applications.
Qt empowers productivity across the entire product development lifecycle, from UI design and software development to quality assurance and deployment. Find the solution that best suits your needs.
Insight into the evolution and importance of user-centric trends and strategies.
Learn how to shorten development times, improve user experience, and deploy anywhere.
Tips on efficient development, software architecture, and boosting team happiness.
Get the latest resources, check out upcoming events, and see who’s innovating with Qt.
Whether you're a beginner or a seasoned Qt pro, we have all the help and support you need to succeed.
May 19, 2022 by Ulf Hermann | Comments
This is the second installment in the series on how to adjust your QML application to take the maximum advantage of qmlsc. In the first post we've set up the environment and taken an initial measurement. I highly recommend reading that one first. What we've measured was the time the updateLockButton() function in ButtonsBar.qml takes before we optimize it. It was 61.4µs for an aggregation of 8 calls, or 7.67µs for each single call on average (which is not statistically significant, but good enough for demonstration purposes).
Now, let's go back to the warning we've seen. What is qmlsc actually complaining about? It doesn't find a type annotation on the "updateLockButton" function. This means it doesn't know of what type the "locked" parameter to the function is. Therefore, it cannot compile the function to C++. Well, this is easy to fix. "locked" is obviously a boolean, and we can state this:
function updateLockButton(locked: bool) {
lockButton.checked = !locked;
}
Let's make this change and compile and profile again the same way. Notice that the compiler warning has disappeared. Did it make a difference? On my machine the statistics now show a cumulative time of 30.1µs, with each call taking 3.76µs on average.
Again, this is not a statistically significant measurement, but it shows how you can get a feeling for the impact of your changes.
You see a similar warning for the "logButtonChecked()" function:
Warning: ButtonsBar.qml:46:27: Could not compile function lockButtonChecked: function without type annotation returns bool of QQuickAbstractButton::checked with type bool
return lockButton.checked;
This means the compiler wants to see a return type annotation. The function obviously returns a boolean, so this is also easy to fix:
function lockButtonChecked(): bool {
return lockButton.checked;
}
The types you can use as annotation are QML types. They are distinct from JavaScript types. In particular, you can use value types and object types. You can explicitly specify "void" as return type in order to mark a function without arguments or return value as typed. The documentation for value types has recently been updated. You may need to look at the documentation snapshot for the latest version.
So, for example, you can have "int", "real", "vector2d", or "Rectangle" as type annotation, but not "object" or "number". "string" is a QML type as well as a JavaScript type.
A description of type annotations from the perspective of invoking the functions from C++ is also available in the documentation.
The fundamental concept of type annotations has been part of the language since Qt 5.14. "void" has been a builtin QML type since Qt 6.2.3.
Download the latest release here: www.qt.io/download.
Qt 6.8 release focuses on technology trends like spatial computing & XR, complex data visualization in 2D & 3D, and ARM-based development for desktop.
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Oct 10, 2024
We’re very happy to announce the latest release of Qt for Python 6.8. With..
Oct 1, 2024
We are happy to announce the release of Qt Creator 14.0.2! In addition to..
Sep 20, 2024
Qt Gradle Plugin 1.0 (QtGP) build tool has been released. You can include..
Qt Group includes The Qt Company Oy and its global subsidiaries and affiliates.