Skip to content

KDAB contributions to Qt 5.4: qmllint

One type of bug I see very often comes down to syntax errors in QML and JavaScript files. Most of the time these errors are simple typos; however, they creep in, go unnoticed by continuous integration and sometimes reach production — especially on delayed loaded components.

I like fixing bugs, but what I love even more is not fixing them, so I wrote a command line tool that can easily be integrated into our CI system so we can nip them in the bud at build time.

Enter qmllint: a command line QML syntax checker. Example usage:

$ qmllint ClickableImage.qml
ClickableImage.qml:17 : Expected token `numeric literal'

Verifying all files:

$ find -type f -name \*qml -exec qmllint \{\} +
./qml/SettingsPage.qml:35: Unexpected token `if'
./qml/AboutPage.qml:35: Expected a qualified name id

qmllint comes with Qt 5.4 and lives alongside other Qt tools.

Furthermore, I would also recommend using other linter tools in your project, such as json_verify or xmllint. Do not do manually what could be automated by the build system!


qmllint cannot catch semantic errors. There are cases where QML files are syntactically correct but have other types of problems:

Bar.qml:1 TypeFoo is not a type
Bar.qml:2 module "QtQuickControls" is not installed
Bar.qml:6:9: QML Rectangle: Cannot anchor to an item that isn't a parent or

There are no plans on my part to make this tool smarter, I like the “do one thing and do it well” philosophy, so it is finished. Checking for these kinds of mistakes is also very difficult, f.i. because we would need to depend on the QML context of a running application.

But don’t worry, my next blog post will address automating semantic validation, so stay tuned!


Categories: KDAB Blogs / KDAB on Qt

4 thoughts on “KDAB contributions to Qt 5.4: qmllint”

  1. Will that also get into qt creator? I personally prefer command line but it would be also nice to run this at the build step in qt creator.

  2. Really handy tool, thanks for sharing!

    Petar, I guess you can already use it with your projects with a QMAKE_EXTRA_TARGETS pre step which would then also be performed within Qt Creator builds?

Leave a Reply

Your email address will not be published. Required fields are marked *