Printing Console output to Widget.



  • 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?



  • 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/



  • 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.



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



  • 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.



  • 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.


  • Moderators

    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).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.