Results 1 to 2 of 2

Thread: Redirect Cout from Static Library Calls running in QThread

  1. #1
    Join Date
    Nov 2010
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Redirect Cout from Static Library Calls running in QThread

    Hello all,

    I'm working on a program which makes many lengthy calls to an external library, which typically prints a large amount of diagnostic information to cout. I'd like to call this library from a separate QThread so my GUI remains responsive, but I would also like to redirect the cout to a QPlainTextEdit for the user to see.

    I have looked into initializing a QDebugStream for the QThread to redirect the cout to the GUI, but it doesn't seem to suit me as it modifies the QPlainTextEdit directly via a pointer, and the GUI cannot be modified by a QThread except by signals.

    Is there a standard way to do this that I have overlooked in my Google/Stackoverflow searches?

    Regards,
    Kyle

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Redirect Cout from Static Library Calls running in QThread

    The standard input/output/error streams are shared resources, i.e. all threads use the same ones.

    So this is not a question of threading at all.

    If you only want to redirect output of that library, my suggestion would be to create a helper program that runs that operation.
    You can then run this program with QProcess and handle its output however you'd like.

    Also solves the "keeping UI responsive" task.

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 20th December 2012, 12:48
  2. Replies: 1
    Last Post: 4th October 2012, 14:49
  3. Replies: 2
    Last Post: 19th February 2011, 11:26
  4. Replies: 4
    Last Post: 27th March 2008, 09:21
  5. Polymorphism with static calls
    By niko in forum General Programming
    Replies: 12
    Last Post: 9th November 2007, 09:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.