Results 1 to 4 of 4

Thread: IPC / reading stdin within non-GUI thread

  1. #1
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default IPC / reading stdin within non-GUI thread

    [ Qt 4.3.2 / Windows ]

    I wish to pass (small amounts of) information from a "parent" process to spawned "child" processes.
    To do this I am attempting to:
    QProcess::write() text information from within the "parent" process to a "child" process's standard input.
    QTextStream::read() text information from standard input within a "child" process.

    To test this idea, I mocked up 2 applications, each with a button ... the "parent" application button action would perform the write, the "child" application button action would perform the read. This was SUCCESSFUL in transferring the information.

    Because placing QTextStream::read() in a GUI thread will hang the GUI until there are bytes to read, I moved the "child" application logic to a background thread. NOW it does NOT work ... the "child" process never sees any bytes received.

    I am thinking this is what is happening: Only a GUI thread can see standard input.
    Am I correct? or should I keep looking for am implementation error on my part. (I have been looking and debugging a lot to arrive at this conclusion.)

    I can supply code, but first I thought perhaps someone would know if my approach was even valid to pursue.

    Thank y'all for any/all feedback.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: IPC / reading stdin within non-GUI thread

    Quote Originally Posted by mule View Post
    Because placing QTextStream::read() in a GUI thread will hang the GUI until there are bytes to read, I moved the "child" application logic to a background thread. NOW it does NOT work ... the "child" process never sees any bytes received.
    Use QIODevice::bytesAvailable() before calling read(). If it's 0, don't read at all - no need for other threads.

  3. #3
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: IPC / reading stdin within non-GUI thread

    I thought of that ... using QIODevice::bytesAvailable() was in an earlier attempt. (Actually, it was QTextStream::device()->bytesAvailable() that I tried.)
    For that case, 0 was ALWAYS returned, so I did not pursue that any further. (Perhaps I had an error or misunderstanding with that attempt ... or, perhaps there was a buffering conflict ...)

    [ It is dinner time here and I am being called home ... will return in the morning ... ]

    [ Just realized I will be out-of-town all day tomorrow, so may be a while before I see posts ... ]

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: IPC / reading stdin within non-GUI thread

    In that case connect to the readyRead signal of QProcess and read only when there is anything to be read.

Similar Threads

  1. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  3. Replies: 10
    Last Post: 20th March 2007, 22:19
  4. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  5. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44

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.