How Qt - Qml debugging and / or profiling?

What Qt / QML software parts are needed to compile in the application in order to be able to debug / QML profile?

My current application is built using cmake and runs on an embedded device. Also, I'm starting to use Qt 4.8.3 (still 4.7.0).

I would like to use these fancy / cool features (for the embedded developer):

http://doc.qt.digia.com/qtcreator/creator-qml-performance-monitor.html

I searched the qt-project deflection, looking for help, but I did not understand what steps are needed when you want a debug / profile remote application with a custom build environment.

So, I would like to know if any of the following steps are needed, and in the positive case, which is actually the necessary code.

  • Qt./ libraries configure specific parameters.
  • QtCreator options for attaching / starting to a remote application.
  • Cmake includes the libraries necessary for the final execution of the application.

Any help, link, etc. is appreciated.

+8
c ++ qt embedded cmake qml
source share
5 answers

With Qt 4.8, this has become pretty easy. All the necessary libraries are now part of Qt itself, and you do not need to create your own debug library for your version of Qt.

I am developing a Qt / QML desktop application also built with CMake. I had to follow these steps to enable QML debugging:

  • Include the debugging tool in the application startup code

    #include <QtDeclarative/qdeclarativedebug.h> /* [...] */ QDeclarativeDebuggingEnabler enabler; 
  • Add QML_DISABLE_OPTIMIZER=1 to my application runtime

    This can be done in Qt Creator on the runtime tab of the project page.

  • Check the box for debugging QML, also found on the runtime tab.

    This adds the required command line options for communication between Qt Creator and the QML debugging component built into the application.

If everything goes well, the application welcomes you with the following output if it is running in debug mode:

Qml debugging is enabled. Use it only in a safe environment!
QDeclarativeDebugServer: Waiting for connection on port 3768 ...
QDeclarativeDebugServer: connection established

After that, I was able to set breakpoints and check the variables. I also worked on the profiler, accessible through the analysis page.

Your case is obviously a little more complicated as you are developing an embedded application.

Qt creator does not support the deployment and execution of CMake-based projects on embedded platforms. You will have to do it yourself. Remember to pass the necessary arguments to your application to configure QML debugging:

 $ your-app -qmljsdebugger=port:3768,block 

To attach Qt Creator to remote launch of the application for the profiling session, use the corresponding “External” entries in the “Analysis” menu in the Qt Creator main menu. Where is a similar debugging option with "Connect to Debug-Server" under "Debug"> "Debug".

+12
source share

I use Qt 5 and it just got easier. Only one step was required on my side to profile QML:

 #include <QQmlDebuggingEnabler> ... QQmlDebuggingEnabler enabler; 
+6
source share

By checking the docs , all the answers provided seem unnecessary. He then fixes the debugging code in releases. I don’t know why QQmlDebuggingEnabler needed, but if you check the code here and here , you will realize that setting QQmlDebuggingEnabler not needed. Just enable QQmlDebuggingEnabler and set the QT_QML_DEBUG flag, for example. how is it (CMake)

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG ")

However, according to docs, QQmlDebuggingEnabler not required.

Furtermore: profiling unoptimized code makes no sense.

For me, setting the QT_QML_DEBUG flag as a flag and checking the flag to debug QML is enough.

+3
source share

Here is a “cleaner” alternative to @sebasgo answer , paragraph 1.

If you are using Qt5 with QtQuick2, you need to define QT_QML_DEBUG before including QtQuick in some file (it doesn’t matter which file if it is part of the executable). For example, just run main.cpp using the lines:

 #define QT_QML_DEBUG #include <QtQuick> 

It won’t hurt if you use the compiler -DQT_QML_DEBUG flag -DQT_QML_DEBUG (for example, through qmake DEFINES or cmake add_definitions , possibly only in debug builds.

If you are stuck in legacy QtQuick1 (in Qt5 or Qt4), use the QT_DECLARATIVE_DEBUG macro instead, for example

 #define QT_DECLARATIVE_DEBUG #include <QtDeclarative> 

For the curious, here is the corresponding Qt source, short and intuitive:

+2
source share

With Qt 5.1, a new qInstallMessageHandler function has been added . This will allow you to catch and log errors and warnings so that you can handle them on your own.

-2
source share

All Articles