PDA

View Full Version : QProcess readyRead() and readReadStandardOutput signals not triggered in kde



jemesa
27th October 2010, 21:40
The code below takes the command runs linux "root -spy -xprop _NET_ACTIVE_WINDOW", this command returns the id of the active window every time it changes. I would pick the return of this command and add it to a TextEdit. In ubuntu (GNOME) it works right, every time I switch the active window is the signal emitted readReadyStandardOutput and the result is added to TextEdit, but in Kubuntu (KDE), the signal readReadyStandardOutput is not emitted immediately, only after the alternate active window several times is that it is fired. I think it is a problem buffer I / O but can not solve it. When I use QIODevice:: Unbuffered, occours the problem: only write device. Does anyone know how to solve this problem?



#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
process = new QProcess(this);
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(appendText()));
process->start("xprop -spy -root _NET_ACTIVE_WINDOW");
}

void MainWindow::appendText(){
ui->textEdit->append(process->readAll());
}

high_flyer
27th October 2010, 21:51
only after the alternate active window several times is that it is fired.
It could be that its just time that takes the process to start.
Try connecting a slot to the "started()" signal, and only then do the switching between windows, and see if you get the signals then.

jemesa
27th October 2010, 22:01
does not work, the process is already started, as I said the problem only occurs in kde, gnome works normal. Let me explain: the signal is issued only after I switch the window 10 times, then he inserts the ids of 10 windows in TextEdit, then, only after switching to 10 times he inserts again, it's like waiting to fill a buffer to send the signal.

wysota
27th October 2010, 23:30
Maybe you are reading from the wrong channel? What is the current channel of the process?

jemesa
28th October 2010, 01:28
Maybe you are reading from the wrong channel? What is the current channel of the process?

is the default channel of the process, not changed, the code is exactly the one shown above. What I find strange is that it works on Linux distributions with gnome interface but not working on distributions with kde interface.

wysota
28th October 2010, 02:07
And what happens if you run xprop directly from the console? Do you get the output desired on both kde and gnome?

jemesa
28th October 2010, 11:42
Yes, it works with both gnome and kde, and when setting the QProcess channel for ForwardedChannels, the console output occurs in real time in both kde and gnome.

wysota
28th October 2010, 12:05
Are you sure the output goes to stdout and not stderr?

jemesa
28th October 2010, 12:33
I tried changing the channel mode to MergedChannels and not solved.