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
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(appendText()));
process->start("xprop -spy -root _NET_ACTIVE_WINDOW");
}
void MainWindow::appendText(){
ui->textEdit->append(process->readAll());
}
#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());
}
To copy to clipboard, switch view to plain text mode
Bookmarks