When debugging an application, outputting some log is a common method. QML provides multiple APIs for log output, commonly known as Console.log (), which outputs the contents of a parameter directly. Console.log (): Also similar to Console.log () is Console.debug ()/info ()/warn ()/error (), using the following function Console_log () {Console.lo G ("This was Console.log ()") Console.debug ("This is Console.debug ()") Console.info ("This is Console.info ()") Console.warn ("This was Console.warn ()") Console.error ("This is Console.error ()")}console.assert (): with C + + 's ERT Similar, the success is silent, the failure will output the Assert content and related file path, line number, function name and other information, use as follows: function Console_assert () {Console.assert (1 = = 1, "Asse RT 1 = = 1 ")//Success Console.assert (1 = = 2," assert 1 = = 2 ")//Failure Console.assert (1 < 2," assert 1 < 2 ")//Success Console.log (" Assert Ends ")}console.time (): Console.time () used with console.timeend () to output the process between the two functions The time of the order execution, in milliseconds, the function parameters are special (to correspond), use the following: function Console_time () {console.time ("wholefunction")//function Parameters Wholefunction Console.time ("Firstpart")//function parameter Firstpart for (index = 0;Dex < 10000; index++) {//Do something} console.timeend ("Firstpart")//function Parameters Firstpart console.time ("Secondpart") function parameters Secondpart for (index = 0, index < 10000; index++) {//Do something} console.timeend ("Se Condpart ")//function parameter Secondpart for (index = 0, index < 10000; index++) {//do something} console.t Imeend ("wholefunction")//function parameter Wholefunction}console.trace (): The output code executes the stack information of the line number, function name, file path, etc., up to 10, For example the MAIN.QML code is as follows: Import QtQuick 2.2Item {width:360 height:360 function console_trace () {console.trace () Call Console.trace ()} mousearea {anchors.fill:parent onclicked:console_trace ()}} when you click the mouse, output the following log : Console_trace (Qrc:///main.qml:8) onclicked (qrc:///main.qml:13) Console.count (): Outputs the number of times a code block was executed, For example the MAIN.QML code is as follows: Import QtQuick 2.2Item {width:360 height:360 function Console_count () {Console.count ("C Onsole_count () called ")//Call Console.count ()} Mousearea {anchors.fill:parent onclicked: {console_count () Console_count ()}}} When you click the mouse, the output is as follows Log:console_count () Called:1console_count () Called:2console.profile (): QML and JavaScript code performance analysis, Console.profile () is used in conjunction with Console.profileend (), as follows: function f () {console.profile ()//Call some function, the needs to Be profiled. Ensure a client is attached before ending the profiling session. Console.profileend ()} In addition, QML performance analysis can be performed through the ANALYZE->QML Profiler in Qtcreator. Console.exception (): Output exception information, including line number, function name, file path, etc., using the following: function Console_exception () {console.exception ("This was an ex Ception ")}
What is the console API for Qt QML