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 log all application printouts in QML?
Forum Updated to NodeBB v4.3 + New Features

How to log all application printouts in QML?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 1.9k Views 2 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.
  • C Offline
    C Offline
    Curtwagner1984
    wrote on 10 Jul 2017, 18:14 last edited by
    #1

    Hello, I'm trying to figure out if it's possible to display everything that is displayed in the QT-Creator output tab inside a QML text element as the application runs for logging and debug purposes...

    A 1 Reply Last reply 10 Jul 2017, 21:58
    0
    • C Curtwagner1984
      10 Jul 2017, 18:14

      Hello, I'm trying to figure out if it's possible to display everything that is displayed in the QT-Creator output tab inside a QML text element as the application runs for logging and debug purposes...

      A Offline
      A Offline
      ambershark
      wrote on 10 Jul 2017, 21:58 last edited by
      #2

      @Curtwagner1984 It would be quite easy as long as you have a C++ side to your QML app. All that stuff is done via stdout/stderr so you could capture that and push it to a QML widget.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      C 1 Reply Last reply 11 Jul 2017, 11:46
      0
      • J Offline
        J Offline
        Jacob.zhang
        wrote on 11 Jul 2017, 01:06 last edited by
        #3

        qInstallMessageHandler

        1 Reply Last reply
        0
        • A ambershark
          10 Jul 2017, 21:58

          @Curtwagner1984 It would be quite easy as long as you have a C++ side to your QML app. All that stuff is done via stdout/stderr so you could capture that and push it to a QML widget.

          C Offline
          C Offline
          Curtwagner1984
          wrote on 11 Jul 2017, 11:46 last edited by
          #4

          @ambershark

          I have a C++ side, but sadly I'm not sure how to redirect stdout/stderr to QML, is it an event ?

          @Jacob.zhang said in How to log all application printouts in QML?:

          qInstallMessageHandler

          A little elaboration would go a long way.

          A 1 Reply Last reply 11 Jul 2017, 18:27
          0
          • C Curtwagner1984
            11 Jul 2017, 11:46

            @ambershark

            I have a C++ side, but sadly I'm not sure how to redirect stdout/stderr to QML, is it an event ?

            @Jacob.zhang said in How to log all application printouts in QML?:

            qInstallMessageHandler

            A little elaboration would go a long way.

            A Offline
            A Offline
            ambershark
            wrote on 11 Jul 2017, 18:27 last edited by
            #5

            @Curtwagner1984 There's many examples on how to capture stdout/stderr in both raw C, C++ and with Qt, so I'll let you just google that.

            As for connecting the C++ with QML you can just send events or update your qml widget directly with C++. You can find it as a QObject and work directly on it's members.

            Something like this:

                auto passwordField = qmlObject_->findChild<QObject *>("pwField");
                if (!passwordField)
                {
                    so << "failed to find pwField" << endl;
                    return false;
                }
            
                connect(passwordField, SIGNAL(accepted(QString)), operators_, SLOT(login(QString)));
            

            In this code I have an accepted(pin) signal in my qml that talks to my C++ side for verification. That then calls a loginResult() function in my qml object.

            I can't share all the code since I wrote it for a client and it's not mine to share, but you can find plenty of information on how to do that in the qmlbook online:

            https://qmlbook.github.io

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            C 1 Reply Last reply 12 Jul 2017, 12:16
            2
            • A ambershark
              11 Jul 2017, 18:27

              @Curtwagner1984 There's many examples on how to capture stdout/stderr in both raw C, C++ and with Qt, so I'll let you just google that.

              As for connecting the C++ with QML you can just send events or update your qml widget directly with C++. You can find it as a QObject and work directly on it's members.

              Something like this:

                  auto passwordField = qmlObject_->findChild<QObject *>("pwField");
                  if (!passwordField)
                  {
                      so << "failed to find pwField" << endl;
                      return false;
                  }
              
                  connect(passwordField, SIGNAL(accepted(QString)), operators_, SLOT(login(QString)));
              

              In this code I have an accepted(pin) signal in my qml that talks to my C++ side for verification. That then calls a loginResult() function in my qml object.

              I can't share all the code since I wrote it for a client and it's not mine to share, but you can find plenty of information on how to do that in the qmlbook online:

              https://qmlbook.github.io

              C Offline
              C Offline
              Curtwagner1984
              wrote on 12 Jul 2017, 12:16 last edited by
              #6

              @ambershark

              Thank you, I'll try that and report back...

              1 Reply Last reply
              0

              6/6

              12 Jul 2017, 12:16

              • Login

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