Debugging QML Applications

Source: Internet
Author: User

Debugging QML Applications

Console Apilog

console.log, Console.debug, Console.info, Console.warn and console.error can be used to print debugging information to the console. For example:

function F ( Span class= "PLN" >a, B) { Console. ( "A is" , a< span class= "operator" >,  "B is" ,< Span class= "PLN" > B); }             /span>              

The output is generated using the Qcdebug, Qcwarning, qccritical methods in C + +, with a category of "QML" or "JS", Dependi Ng on the type of file doing the logging. See also debugging techniques.

Assert

console.assertTests. An expression is true. If not, it would write a optional message to the console and print the stack trace.

functionF() { VarX= 12 Console.< Span class= "KWD" >assert (x ==< Span class= "PLN" > 12,  "This would pass"  Consoleassert (x > Span class= "number" >12,  "This would fail" ); }             /span>                
Timer

console.timeand Console.timeend Log the time (in milliseconds) is spent between the calls. Both take a string argument that identifies the measurement. For example:

functionF() {Console.Time "wholefunction" . Time "Firstpart" //first part Console. "Firstpart" //second part Console.timeend ( "wholefunction"  ); }             /span>                
Trace

console.tracePrints the stack trace of the JavaScript execution at the point where it is called. The stack trace info contains the function name, file name, line number and column number. The stack trace is limited to last stack frames.

Count

console.countPrints the current number of times a particular piece of code have been executed, along with a message. That's,

function F(){ console.  Count("F called");}         

Would print f called: 1 , f called: 2 ... whenever is f() executed.

Profile

console.profileTurns on the QML and JavaScript profilers. Nested calls is not supported and a warning would be printed to the console.

console.profileEndTurns off the QML and JavaScript profilers. Calling this function without a previous call to Console.profile would print a warning to the console. A profiling client should has been attached before this call to receive and store the profiling data. For example:

function F(){ console.  Profile();  Call some function, needs to be profiled. //ensure A client is attached before ending//the profiling session. Console.  Profileend();}              
Exception

console.exceptionPrints an error message together with the stack trace of JavaScript execution at the point where it is called.

Debugging Module Imports

The QML_IMPORT_TRACE environment variable can set to enable debug output from QML ' s import loading mechanisms.

For example, the simple QML file as this:

ImportQtQuick2.3Rectangle{width:+;  Height:           

If you set QML_IMPORT_TRACE=1 before running the QML Scene (or your QML C + + application), you'll see output similar to th is:

Qqmlimportdatabase::Addimportpath"/qt-sdk/imports"Qqmlimportdatabase::Addimportpath"/qt-sdk/bin/qmlviewer.app/contents/macos"Qqmlimportdatabase::Addtoimport0x106237370 "." -1.-1 File As  "qqmlimportdatabase :: addtoimport 0x106237370  "Qt"  4.7 Span class= "Typ" >library as   "qqmlimportdatabase :: resolvetype  "Rectangle"  =  "Qdeclarativerectangle"    
QML Debugging Infrastructure

The Qt QML module provides services for debugging, inspecting, and profiling applications via a TCP port.

Enabling the Infrastructure

Explicitly enable the debugging infrastructure when compiling your application. If You use Qmake, you can add the configuration parameters to the project. Pro file:

    • Qt Quick 1:CONFIG+=declarative_debug
    • Qt Quick 2:CONFIG+=qml_debug

If You use some other build system, you can pass the following defines to the compiler:

    • Qt Quick 1:QT_DECLARATIVE_DEBUG
    • Qt Quick 2:QT_QML_DEBUG

Note:enabling the debugging infrastructure might compromise the integrity of the application and system, and therefore, Y OU should only enable it in a controlled environment. When the infrastructure is enabled, the application displays the following warning:

QML debugging is enabled. Only use this in a safe environment.

Starting applications

Start the application with the following arguments:

-qmljsdebugger=port:<port_from>[,port_to][,host:<ip address>][,block]

Where port_from (mandatory) specifies either the debugging port or the start port of a range of ports when port_to are is specified, ip address(optional) specifies the IP address of the host where the application is running, and block (optional) prevents the application from running until the debug client connects to the server. This enables debugging from the start.

After the application have successfully started, it displays the following message:

QML Debugger: Waiting for connection on port <port_number>

Connecting to Applications

When the application was running, an IDE or a tool that implements the binary protocol can connect to the open port.

QT provides a qmlprofiler command line tool to capture profiling data in a file. To run the tool, enter the following command:

qmlprofiler -p <port> -attach <ip address>

Debugging with Qt Creator

QT Creator uses the debugging infrastructure to debug, inspect and profiles QT Quick applications on the desktop as well as on remote devices. Qt Creator provides integrated clients for debugging JS, inspecting the object tree, and profiling the activities of a QML Engine. For more information, see QT creator:debugging qt Quick Projects.

Reference Links:

Http://doc.qt.io/qt-5/qtquick-debugging.html

Http://doc.qt.io/qtcreator/creator-debugging-helpers.html

Debugging QML Applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.