Debugging applications¶
QML debugging¶
InCore apps can be debugged easily using the builtin QML debugger in Qt Creator. Before starting, the debugger settings have to be adjusted. Open the Run Settings of your project, scroll down to the Debugger settings and ensure Enable C++ is not checked whereas Enable QML is (Fig. 16).
Type the example code implementing a simple timer which increments a variable every second:
import InCore.Foundation 2.0
Application {
Timer {
property int foo: 0
onTriggered: {
foo++
}
}
}
Now start debugging by clicking the green debug button in the left handed menu or by pressing F5. The program will start running and you can inspect all properties in realtime through the Locals view on the right side. Expand Application
, Timer
and Properties
to see foo
being incremented every second (Fig. 17).
Next set a breakpoint at the code line that increments foo
(click left to the line number). This will make the program being interrupted whenever this code line is executed (Fig. 18). You can inspect and even modify the properties of the local object (and navigate through the object hierarchy via the parent
property). For example you can change the interval
property and observe an appropriate behaviour change.
Further information on debugging QML applications can be found in the Qt Creator Manual (ignore the parts specific to QML user interfaces).
InCore debugging¶
All InCore modules provide additional debug messages which can be enabled easily by setting the Application.debug property to true
. When enabled, extra messages will be logged to the console, especially all error codes and strings whenever an error occurs in any object (which saves adding an onErrorOccurred
handler to every object). Some additional messages also indicate code locations or invalid values causing the actual errors.
To debug applications without modifying them, you can alternatively set the INCORE_DEBUG
environment variable prior to executing incore-cli run ...
. Set the variable either at the command line when running incore-cli
manually anyway or modify the project’s Run Environment and add the corresponding environment variable.
To further increase the verbosity level, internal InCore function calls can be traced. This can be enabled by setting the Application.trace property to true
or setting the INCORE_TRACE
environment variable. When tracing is enabled, your console will likely be flooded with messages unless your application is very small or static. Consider setting a log message filter as described in section Customizing message logging.
Customizing message logging¶
In order to customize the format of log messages or add meta data fields such as a formatted time you can either modify the Application.messageLoggingPattern property or set the QT_MESSAGE_PATTERN
environment variable accordingly (see section InCore debugging on how to do this in Qt Creator). See the Qt documentation on message patterns for details and all supported placeholders.
To filter messages you can set the Application.messageLoggingFilterRules property or set the QT_LOGGING_RULES
environment variable. See the property documentation for details on syntax and supported values.