[Qt-qml] Enabling QML JS debugging with a CMake project

kai.koehne at nokia.com kai.koehne at nokia.com
Fri May 20 09:22:38 CEST 2011


Hi,

Perfect summary Thomas! Let me add that this will be less hassle with 4.8: The helper classes in static library + the glue code needed in the user code are then part of Qt itself, and all you need to do is adding a CONFIG+=declarative_debug, as well as setting the QML_DISABLE_OPTIMIZER variable. 
	
Regards

Kai

> -----Original Message-----
> From: qt-qml-bounces+kai.koehne=nokia.com at qt.nokia.com [mailto:qt-
> qml-bounces+kai.koehne=nokia.com at qt.nokia.com] On Behalf Of ext
> Thomas McGuire
> Sent: Thursday, May 19, 2011 8:49 PM
> To: qt-qml at qt.nokia.com
> Subject: Re: [Qt-qml] Enabling QML JS debugging with a CMake project
> 
> Hi Matt,
> 
> you're on a good track so far, after building the debugger helper library
> libQmlJSDebugger.a and adding the QMLJSDEBUGGER definition.
> 
> Some more things are needed:
> - Enable the "QML" checkbox under Sidebar->Projects->Run Settings
> - Add QML_DISABLE_OPTIMIZER as an environment variable, with the value
> "1"
> - You already use -qmljsdebugger=port:3768, though you use a different
> port, I
>   guess you've changed that in QtCreator settings as well, right?
> 
> You'll also need changes to the actual code of the project. I found this out by
> creating a new project with the wizard in QtCreator and then copying the
> code from there.
> 
> First of all, you need to have the include directory from the QML debugging
> helper library in your include path, I used the following in my CMake file:
> include_directories(${QT_BINARY_DIR}/../qtc-qmldbg/include/)
> The path may vary for you of course.
> 
> Next, change the code, best is the .cpp file in which your main
> QDeclarativeView is created. Near the top of the file:
> > #if defined(QMLJSDEBUGGER)
> > #include <qt_private/qdeclarativedebughelper_p.h>
> > #endif
> >
> > #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER) #include
> > <jsdebuggeragent.h> #endif #if defined(QMLJSDEBUGGER) &&
> > !defined(NO_QMLOBSERVER) #include <qdeclarativeviewobserver.h>
> #endif
> >
> > #if defined(QMLJSDEBUGGER)
> >
> > // Enable debugging before any QDeclarativeEngine is created struct
> > QmlJsDebuggingEnabler {
> >     QmlJsDebuggingEnabler()
> >     {
> >         QDeclarativeDebugHelper::enableDebugging();
> >     }
> > };
> >
> > // Execute code in constructor before first QDeclarativeEngine is
> instantiated
> > static QmlJsDebuggingEnabler enableDebuggingHelper;
> >
> > #endif // QMLJSDEBUGGER
> 
> That is what the QMLJSDEBUGGER definition was for, btw.
> 
> Then, near the place where you create the declarative view:
> 
> > #if defined(QMLJSDEBUGGER) && !defined(NO_JSDEBUGGER)
> >     new QmlJSDebugger::JSDebuggerAgent(m_qmlScene->engine());
> > #endif
> > #if defined(QMLJSDEBUGGER) && !defined(NO_QMLOBSERVER)
> >     new QmlJSDebugger::QDeclarativeViewObserer(m_qmlScene, this);
> > #endif
> 
> m_qmlScene is the QDeclarativeView in my project, IIRC.
> 
> Those should be all the steps you need, good luck!
>
> Regards,
> Thomas
> 
> On Thursday, May 19, 2011 07:30:51 PM Matt Thomas wrote:
> > Hello, I'm trying to get QML JS debugging to work with a generic
> > project type (ie I don't have a .pro file and I don't use qmake).
> > Instead I use the CMake tool and CMakeLists.txt to attempt to link in
> > the necessary qml js library, but it is not working. I came up with
> > the following CMake directives by reading through a Makefile
> > generating by a standard QtQuick application project wizard.
> > Essentially I add -DQMLJSDEBUGGER define to my cflags and then link
> against libQmlJSDebugger.a.
> >
> >  # Qml Debugging
> >  INCLUDE_DIRECTORIES("/opt/qt/4.7.4/qtc-qmldbg/include")
> >  SET(QMLDBG_LIBRARIES /opt/qt/4.7.4/qtc-qmldbg/libQmlJSDebugger.a)
> >  SET(CMAKE_CXX_FLAGS "-DQMLJSDEBUGGER")
> > TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${QMLDBG_LIBRARIES})  #
> End Qml
> > Debugging
> >
> > The application links successfully (I have built the
> > libQmlJSDebugger.a file independently) but when I attempt to run it gives
> an error message.
> >
> >  $ bin/app -qmljsdebugger=1234
> >  QDeclarativeDebugServer: Ignoring "-qmljsdebugger=1234". Debugging
> > has not been enabled.
> >
> >
> > Is there anything extra I need to do to manually pull in the QMLJS
> > debugging libraries?  I cannot use a standard Qt qmake project because
> > my project requires CMake for other reasons.
> >
> > My apologies if this is not the correct list topic, but qt-qml seemed
> > to be the closest to my issue.
> >
> > Thanks,
> > --Matt
> 
> --
> Thomas McGuire | thomas.mcguire at kdab.com | Software Engineer KDAB
> (Deutschland) GmbH&Co KG, a KDAB Group company Tel. Germany +49-30-
> 521325470, Sweden (HQ) +46-563-540090 KDAB - Qt Experts - Platform-
> independent software solutions


More information about the Qt-qml mailing list