Results 1 to 9 of 9

Thread: Display an output buffer (text stream) in QWidget

  1. #1
    Join Date
    May 2011
    Posts
    22
    Qt products
    Qt4

    Default Display an output buffer (text stream) in QWidget

    Hi all,

    1. From my program I run a thread (QThread).
    2. When the thread runs it issues an API for a program called CPLEX (sort of solver).
    3. CPLEX is executed and writes info to the terminal as it runs, just like qDebug() does.

    Through the API, I can give CPLEX an alternate output buffer. Can I use QTextBlock or QTextEdit to display the contents of the alternate output buffer as CPLEX writes to it? How would I implement this?

    Thank you very much!

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display an output buffer (text stream) in QWidget

    I think it depends from CPLEX API.
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    May 2011
    Posts
    22
    Qt products
    Qt4

    Default Re: Display an output buffer (text stream) in QWidget

    How would you display an arbitrary buffer in a QWidget of some sort, while this buffer is written to from another thread?

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Display an output buffer (text stream) in QWidget

    When the thread runs it issues an API for a program called CPLEX (sort of solver).
    If you launch the program using QProcess you can read its output channels and use signals that will notify you if new output from the program is ready. You can then forward the signals up to append(const QString&) slot in text edit (or another mehod that will display new text).

  5. #5
    Join Date
    May 2011
    Posts
    22
    Qt products
    Qt4

    Default Re: Display an output buffer (text stream) in QWidget

    So I need a QProcess. Can I then still used shared memory, signals and slots, etc. ?

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Display an output buffer (text stream) in QWidget

    I don't know if you need a QProcess, this is just a suggestion, suitable for the situation when you need to run external program as separate process and communicate with it.
    Check out the QProcess documentation for details.
    Maybe I just got it wrong, but this sentence: "it issues an API for a program called CPLEX " suggests that you run an external application.

  7. #7
    Join Date
    May 2011
    Posts
    22
    Qt products
    Qt4

    Default Re: Display an output buffer (text stream) in QWidget

    Aha, no this is not the case. It's like this:
    First everything (including the CPLEX implementation) used the same thread.
    Then I moved the solving part to a separate thread (so I could still use the rest of the program).

    It is possible to create a new buffer and hand it over to CPLEX (using the API). But I would like to read it out in real time (using a QWidget).

    What would you suggest?

    Thanks!

  8. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Display an output buffer (text stream) in QWidget

    In that case, a simple signal emitted from the worker thread will do the job.
    Declare a void message(const QString& text) signal in your worker thread, and each time you want to send new message call emit message(message text);, connect this signal to a slot for display in your main widget ( for example append(const QString&) in QTextEdit ) and its done. You don't have to worry about thread-safety in that case, Qt will use queued connections for your signals automatically.

  9. #9
    Join Date
    May 2011
    Posts
    22
    Qt products
    Qt4

    Default Re: Display an output buffer (text stream) in QWidget

    I'll give it a try, thank very much for your help.

Similar Threads

  1. Application Output : MediaSource::Stream not yet handled
    By hrn2k1 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 6th April 2011, 06:19
  2. Replies: 0
    Last Post: 17th March 2011, 19:38
  3. Replies: 2
    Last Post: 29th September 2008, 00:08
  4. QWidget get painter buffer
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 16:43
  5. No output on frame buffer (arm target board)
    By devendra in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 29th November 2006, 20:03

Tags for this Thread

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.