Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Printing Console output to Widget.
Forum Updated to NodeBB v4.3 + New Features

Printing Console output to Widget.

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 12.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
    sabby
    wrote on last edited by
    #1

    When we run any application in QT we gen an Application Output something like the following:

    Starting /home/sarbartha/Desktop/QT Projects/garment/garment...
    aaa
    /home/sarbartha/Desktop/QT Projects/garment/garment exited with code 0

    I want to print this output into a text box in my widget. Can any one help me with this?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jake007
      wrote on last edited by
      #2

      Hi!

      What you wrote in title and what in body of your post, are two completely different things.

      What Qt Creator writes when starting an application, is written directly from code. Process (your app) is started with QProcess class., and in there are also settings for redirecting streams (stdout, stderr...). What you get with cout, print, qDebug into your Qt Creator.

      If you wish to redirect what is printed inside your app into widget in the same application, You'll be very limited. You can only do this with Qt's functions ( qDebug(), qWarning(), QFatal() ...), using "this":http://doc.qt.digia.com/qt/qtglobal.html#qInstallMsgHandler function. But you will not be able to redirect messages for printf, cout and similiar, because Qt application when started standalone starts with stdout and stderr closed ( printf usess it to print messages).
      Read more about it "here":http://qt-project.org/forums/viewthread/23075/


      Code is poetry

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sabby
        wrote on last edited by
        #3

        I want to print what ever prints into the Application Output into a textbox or label in my widget. Can you tell me how to do so.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jake007
          wrote on last edited by
          #4

          Can you give me an example how you print/output your data now?


          Code is poetry

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sabby
            wrote on last edited by
            #5

            for example I run my program and when I closed it I got the following outputs:

            Starting /home/sarbartha/Desktop/QT Projects/garment/garment...
            project loaded...
            aaa
            button closed...
            /home/sarbartha/Desktop/QT Projects/garment/garment exited with code 0


            I want to show the above output into a text box while running the application.... its like showing the logs of the application.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jake007
              wrote on last edited by
              #6

              When your application is started and stopped, you'll have write out yourself in your application and showed in a widget ( ui->textBox->appen("I just started!")).
              For redirect output ( only Qt's functions as written before ( qDebug() etc)), use function as mentioned "before":http://doc.qt.digia.com/qt/qtglobal.html#qInstallMsgHandler.
              Where there are fprintf functions, write your custom one. I'd recommend using signals and slots to do this.

              But be careful when you use it. It will work only after GUI has been set up and before it is destroyed. Otherwise, application will crash.


              Code is poetry

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tobias.hunger
                wrote on last edited by
                #7

                The "Starting ..." line as well as the "... exited with code 0" are generated by Qt Creator. You can not get to that from anywhere in your application.

                You can intercept the rest using a messagehandler (see qInstallMsgHandler in the docs).

                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