Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to write logs into files?
Forum Updated to NodeBB v4.3 + New Features

How to write logs into files?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 5 Posters 15.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sevenjay
    wrote on last edited by
    #1

    I can use console.log to show some message.
    but how to write logs into files?
    It's useful for tracing bugs in different users' device.
    thanks.

    1 Reply Last reply
    0
    • frankcyblogic.deF Offline
      frankcyblogic.deF Offline
      frankcyblogic.de
      wrote on last edited by
      #2

      I'm not sure what console.log is, but the following works:
      @
      QFile myFile(...);
      myFile.open(QIoDevice::WriteOnly);
      QTextStream myLog(&myFile);
      myLog << "Log message" << endl;
      @

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DenisKormalev
        wrote on last edited by
        #3

        unclewerner, your solution is pure C++, not QML :)

        You can overwrite debug ouput handler (in C++) to write in file and use QML console.log as you use it now and all messages will go to file.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Or you use Qxt's QxtLogger, and let that
          a) install itself as the message handler, and
          b) output to the file you want, by setting up the appropriate logger engine (either the QxtBasicFileLoggerEngine or the QxtXmlFileLoggerEngine, in your case).

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mbrasser
            wrote on last edited by
            #5

            Hi,

            As the above comments indicate, there is no "pure-QML" solution to this problem -- you'll need to do some C++ coding in order to write to a file. This could be done by overriding the message handlers, or exposing you own custom function to QML that takes care of the writing. "This page":http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#exchanging-data-between-qml-and-c gives more information on some of the ways to communicate between C++ and QML.

            Regards,
            Michael

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved