QProcess::startDetached and bash stdout capture

David Faure faure at kde.org
Sat Mar 25 15:07:37 GMT 2017


I need help with a shell and child process issue.

To show a progressbar with kdialog, the usage is like this:

dbusRef=`kdialog --progressbar "Initialising" 6`
qdbus $dbusRef Set org.kde.kdialog.ProgressDialog value 1
etc.

i.e. kdialog outputs on stdout a dbus servicename + objectpath, and exits,
while leaving a process running that the shell script can talk DBus to.

In Qt4 times this used to be done with kdialog fork()ing but the new DBus 
thread in QtDBus makes that impossible now with Qt5.

So I have now separated this into two processes:
* kdialog, the parent process that exits as soon as things are set up
* kdialog_progress_helper, the child process that keeps running and answers to 
the dbus calls.

It almost works.
It works when copy/pasting the output of kdialog into qdbus calls :
$ kdialog --progressbar 'YOUR TEXT HERE' 4                         
org.kde.kdialog-1707 /ProgressDialog
$ qdbus org.kde.kdialog-1707 /ProgressDialog value 1

But it doesn't work when using the shell $(...) or `...` syntax to capture 
stdout. The shell just never makes it to the next line, it blocks forever. 
It's like kdialog doesn't exit, but it does... it's shown as <defunct> by 
`ps`, meaning (AFAIK) that it has terminated. The shell just doesn't move 
along, but why?

It's related to QProcess::startDetached, because if I skip calling that then 
the shell is happy to capture stdout and move on.

Bug in QProcess::startDetached ?

I tried close(1) like the kde4 kdialog was doing (due to forking, though), no 
change.

If you want to try, I committed the current state of things in 
https://commits.kde.org/kdialog/da7c7c8218fc55af7706e649449684bc3d2782fb
(and merged to master).

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5





More information about the kde-core-devel mailing list