Debugging Qt Quick 2 - Console API
The focus in this blog post is on debugging and the most straightforward debugging technique: The console API. Chances are high that you've already used it in your first helloworld.qml file, since console.log() is a part of it. We recently updated Qt 5 with some of the most useful methods from the FireBug console API (a defacto standard in web browsers).
Ever wondered about how long a particular code path takes? Take for example the logic in your onCompleted method.
will print the time in milliseconds. The string argument is both an identifier for the particular measurement (you can also make interleaved measurements) and the prefix for the output:
For a more in-depth analysis there's console.profile(), console.profileEnd().
The API pair profiles both the state of the QDeclarativeEngine as well as V8 method calls. However, to retrieve the data you have to attach the QML Profiler tool to your application before calling console.profileEnd() else the profiling data is lost. Christiaan Janssen has already described the QML Profiler tool that ships with Qt Creator in a previous post here. A standalone profiler tool is available in Qt 5 that saves the profiling data in a file. This file can then be read using Qt Creator.
We have also introduced the following APIs:
console.count(): Prints the number of times this function is called along with a user provided message.
Script Console - New Avatar
The QML console was first introduced in Qt Creator 2.1. However, it was a simplified console limited to evaluating simple expressions. We felt that Qt Quick2 developers need a more advanced console to unleash the power of QML.
We introduce to you the new avatar of the QML Console a.k.a. Script Console.
The best thing is that you do not have to wait for too long as the Script Console will be a part of Qt Creator 2.5.
We haven't implemented the methods dealing with the console so far, just because they don't make too much sense when your console is just the command line. For example, it would be hard to implement console.clear() in a portable way ;) We left out console.group(), console.groupCollapsed(), console.groupEnd(), console.table(), console.dir(), console.dirXml() for similar reasons.
The Script Console in Qt Creator is WIP. Currently, QML objects and arrays are not shown in a tree. The console still needs polishing and do expect more features in later versions.
We are eager to hear your wish list and your experiences with the console. You can contact us via the qtcreator mailing list or on IRC at the freenode server, channel #qt-creator.
Subscribe to our newsletter
Try Qt 6.6 Now!
Download the latest release here: www.qt.io/download.
Qt 6.6. is a feature release with focus on improving UX capabilities including responsive UI technology and the Qt Graph module.
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.