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?
QtWS25 Last Chance

How to log all application printouts in QML?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 1.9k Views
  • 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 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
    0
    • C Curtwagner1984

      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 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
      0
      • Jacob.zhangJ Offline
        Jacob.zhangJ Offline
        Jacob.zhang
        wrote on last edited by
        #3

        qInstallMessageHandler

        1 Reply Last reply
        0
        • A ambershark

          @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 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
          0
          • C Curtwagner1984

            @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 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
            2
            • A ambershark

              @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 last edited by
              #6

              @ambershark

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

              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