New in Qt 5.10: Dynamic Language Change in QML

My favourite new feature in Qt 5.10 is the inconspicuous function QmlEngine::retranslate(). Finally, seven years after QML’s birth, there is a Qt way to change the language of your application at runtime. There is no need for workarounds any more (see How to do dynamic translation in QML for the standard workaround).

I wrote a simple application demonstrating the new feature. If we click the British (German) flag on the right-hand side, the language of the labels on the left-hand side is changed accordingly.

How does the dynamic language change work?
Continue reading

Passing Enum Properties between C++ and QML

We have defined a Qt property warningLevel in the C++ class MainModel:

    Q_PROPERTY(WarningLevel::Enum warningLevel READ warningLevel
               WRITE setWarningLevel NOTIFY warningLevelChanged)

We want to use this property in QML. For example, we want to colour a rectangle according to the warningLevel:

    import com.embeddeduse.models 1.0
    // ...

    property MainModel mainModel : MainModel {}

    Rectangle {
        color: toColor(mainModel.warningLevel)
        // ...
    }

    function toColor(level) {
        switch (level) {
        case WarningLevel.Error:
            return "red"
        case WarningLevel.Warning:
            return "orange"
        case WarningLevel.Info:
            return "green"
        case WarningLevel.Debug:
            return "purple"
        default:
            return "magenta"
        }
    }

Note how we access the C++ property mainModel.warningLevel from QML to set the color of the rectangle and how we use symbolic enum constants like WarningLevel.Info in the function toColor().

It is similarly easy to use a list of the symbolic enum constants as the model of a Repeater and to assign the warning level by the user to the property mainModel.warningLevel in the onReleased handler of a MouseArea.

    Repeater {
        model: [WarningLevel.Error, WarningLevel.Warning, WarningLevel.Info,
            WarningLevel.Debug]
        Rectangle {
            color: toColor(modelData)
            // ...
            MouseArea {
                anchors.fill: parent
                onReleased: mainModel.warningLevel = modelData
            }
        }
    }

I’ll show you in the rest of this post how to write your C++ code so that you can use a C++ property of enum type easily in QML.
Continue reading

Announcing My Talk “Qt vs. Web – Total Cost of Ownership” at Qt World Summit 2017

I am proud to announce that my talk “Qt vs. Web – Total Cost of Ownership” was accepted for Qt World Summit 2017. It is scheduled for Thursday, October 12, at 11:30 in the Business track.

I’ll show that Web applications require a considerably more powerful system-on-chip (SoC) than Qt applications to achieve a good user experience. However, a more powerful SoC is also much more expensive, as the following diagram shows.

Hope to see you in Berlin.

I’ll make the presentation slides available immediately after Qt World Summit.

More Reasons For Not Using Web

The Qt Company published a guest post “Qt QML v HTML5 – a practical comparison” and a whitepaper by the Austrian Qt consultancy Sequality. Sequality had one developer writing a simplified application for controlling a bottling plant first with Qt and then with Web (AngularJS). The developer had 160 hours for each implementation. The application had to run on a tablet, a PC and a Raspberry Pi 3 with different resolutions.

Here are my favourite findings of Sequality’s experiment.

  • The developer finished considerably more functionality with QML than with Web.
  • Higher efforts to use OpenGL acceleration for Web: “Enabling GPU rendering on Chromium […] doesn’t fix the HTML5 demo’s performance problem. In fact, the CPU is utilized even more, which leads to overheating.”
  • Higher efforts for testing Web: “The fact that HTML5 applications can be executed on a number of platforms – and a number of browser engines on each platform – multiplies the testing time correspondingly.”
  • Availability of a certain Web technology in 10 years: “Modern HTML5-based applications that use frameworks like AngularJS are relatively new and undergo changes from year to year – a valid question is whether AngularJS (or any other currently trendy Javascript-library) will still be a relevant HTML5-technology in 10 years.”

Using Qt 5.6 and Later under LGPL

Up to Qt 5.3, things were pretty simple. Most modules were under LGPLv2.1 with the exception of some commercial modules. Starting with Qt 5.4, new Qt modules were published under LGPLv3 and old modules additionally under LGPLv3. With Qt 5.6, we now have quite a patchwork of modules under different licenses. Qt 5.7 will drop LGPLv2.1 completely. Some companies stay on Qt 5.3, because they are afraid of LGPLv3. Let me bring some clarity into this patchwork and explain how you can still use Qt under LGPL and sleep well.
Continue reading

Running a QML HMI on an ARM11 without OpenGL

Recently, I brought up Qt 5.5 on a Freescale i.MX35, which has an ARM11 CPU but no OpenGL support. Despite the missing OpenGL, I wanted to write the HMI with QML. The additional challenge was that the cross-compilation toolchain was 32-bit, but I wanted to use my standard 64-bit Ubuntu. I’ll show in this post how to set up the 32-bit toolchain and rootfs on my 64-bit Ubuntu machine, how to configure and build Qt 5.5 from the sources, and how to run a hello-world application written in QML on the i.MX35. Continue reading

Responsive QML HMIs with File Selectors

In my previous post, I have shown how to use scaling to adapt QML HMIs to different screen sizes and formats. We reach the limits of scaling if we must change the structure of the HMI or if the HMI must be pixel-perfect. The solution to these problems is to provide a different implementation for each screen size. Switching between these different implementations is done with QML file selectors.
Continue reading

Responsive QML HMIs with Scaling

The HMIs of in-vehicle infotainment systems, TVs, phones and many other systems must adapt to different screen resolutions and formats. This adaptation should happen with as little duplicate effort as possible. The simplest way of doing this for QML HMIs is to scale the values of all x, y, width, height, margin and border properties in proportion to a reference resolution. Based on the HMI of a music player, I’ll show you how to do this by changing only the screen width and height. Continue reading

Building HMI of Harvester with Qt

At Qt Developer Days 2014 in San Francisco, I gave a talk with title “Case Study: Driver Terminal for Forage Harvester”. I describe the technical challenges and their solutions when I helped Krone to develop the driver terminal of their new BigX 480/580 forage harvesters with QML, Qt and C++. Here are the slides of my presentation and an abstract.
Continue reading

Revolutionary HMI-Design of Forage Harvester

Agricultural OEM Krone bets on Qt software library for development of their terminal / First prototype read in less than three months

Big X in maize harvest at day time

Big X 480 in maize harvest

585 horsepower, 15.6 litres engine displacement and an up to 9 metre wide cutterhead – forage harvesters are among the most powerful agricultural machines. It takes a lot more technology and know-how to drive such a vehicle than a car. The driver terminal of a forage harvester must process information from more than 30 components like motor, cutterhead, metal detector or grinder within tenths of a second. The terminal additionally provides a diagnosis system. The agricultural OEM Krone from Lower Saxony has built all these functions into the touch-screen terminal of its forage harvester Big X 480/580. The HMI software of the terminal was developed with the GUI and application library Qt.
Continue reading