Reputation: 2669
What software Qt/QML pieces are needed to compile in an app to be able to debug/profile QML?
My current app is build using cmake and runs on a embedded device. Furthermore, I'm starting to use Qt 4.8.3 (until now 4.7.0).
I would like to use these fancy/cool features (for an embedded developer):
http://doc.qt.digia.com/qtcreator/creator-qml-performance-monitor.html
I've searched trough qt-project looking for help, but I haven't got clear what are the steps needed when you want to debug/profile a remote app, with a customize build environment.
So, I would like to know if it is needed any of the following steps, and in positive case, what is in fact the needed code.
Any help, link, etc is welcomed.
Upvotes: 12
Views: 27589
Reputation: 16091
Checking the docs all given answers seem to be unnecessary. Further it hardcodes debug code in releases. I have no clue why QQmlDebuggingEnabler
would be necessary, but if you check the code here and here, you will recognize, that the instatiation of QQmlDebuggingEnabler
is not necessary. Just include QQmlDebuggingEnabler
and set the QT_QML_DEBUG
flag e.g. like this (CMake)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG ")
However according to the docs QQmlDebuggingEnabler
is not necessary.
Furtermore: profiling unoptimized code makes no sense.
For me setting QT_QML_DEBUG
as flag and checking the checkbox for QML debugging is sufficient.
Upvotes: 6
Reputation: 10055
I'm using Qt 5, and it got even easier. Just this one step was required on my side to do QML profiling:
#include <QQmlDebuggingEnabler>
...
QQmlDebuggingEnabler enabler;
Upvotes: 7
Reputation: 14471
With Qt 5.1 the new function qInstallMessageHandler was added. It will let you catch, and log, errors and warnings so you can deal with them as you like.
Upvotes: -2
Reputation: 4962
Here is a "cleaner" alternative to @sebasgo's answer, item 1.
If you are using Qt5 with QtQuick2, you only need to define QT_QML_DEBUG
before including QtQuick
in some file (it does not matter what file, as long as it is a part of the executable). For example, it is sufficient to start your main.cpp
with lines:
#define QT_QML_DEBUG
#include <QtQuick>
It won't hurt if you instead use compiler's -DQT_QML_DEBUG
flag (e.g. via qmake DEFINES or cmake add_definitions directives), possibly only in debug builds.
If you are stuck with legacy QtQuick1 (in either Qt5 or Qt4) use QT_DECLARATIVE_DEBUG
macro instead, e.g.
#define QT_DECLARATIVE_DEBUG
#include <QtDeclarative>
For the curious, here is a relevant Qt source, short and self-explanatory:
Upvotes: 3
Reputation: 3851
With Qt 4.8 this got pretty easy. All required libraries are now part of Qt itself and you don't have to build the debug library for your Qt version yourself.
I'm developing a Qt/QML desktop application also built with CMake. I had to complete the following steps to enable QML debugging:
Include the debugging enabler into my application's start-up code
#include <QtDeclarative/qdeclarativedebug.h>
/* [...] */
QDeclarativeDebuggingEnabler enabler;
Add QML_DISABLE_OPTIMIZER=1
to execution environment of my application
This can be done within Qt Creator in the execution tab of the projects page.
Tick the checkbox for QML debugging also found in the execution tab
This adds the required command line parameters for the communication between Qt Creator and the QML debugger component embedded in the application
If everything went fine the application greets you with the following output if started in debug mode:
Qml debugging is enabled. Only use this in a safe environment!
QDeclarativeDebugServer: Waiting for connection on port 3768...
QDeclarativeDebugServer: Connection established
After that I was able to set breakpoints and inspect variables. Also the profiler accessible via the analyze page just worked.
Your case is obviously a little bit more complicated as your developing an embedded application.
Qt creator has no support for deploying and executing CMake-based projects on embedded platforms. You will have to do that yourself. Don't forget to pass the required arguments to your application to configure the QML debugging:
$ your-app -qmljsdebugger=port:3768,block
To attach Qt Creator to a remotely running application for a profiling session use the corresponding "External" entries in the "Analyze" menu in the Qt Creator main menu. Where is a likewise option for debugging with "Connect to Debug-Server" under "Debug" > "Debug".
Upvotes: 13