PDA

View Full Version : Why this code doesn't work?



prykHetQuo
21st January 2009, 18:23
Qt version: 4.4.3.

OS: Ubuntu Linux Desktop Edition 8.10 x86.

The following code does not insert the "ls -hal" output to the QTextEdit object. The QTextEdit object appears empty. Why?

A screenshot is attached.



#include <QApplication>
#include <QDialog>
#include <QProcess>
#include "ui_qsysv-rc-conf.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

Ui::Dialog ui;

QDialog *dialog= new QDialog;

ui.setupUi(dialog);

dialog->show();


QProcess *sysvProcess = new QProcess(dialog);

sysvProcess->start("ls -hal");

const QByteArray &input= sysvProcess->readAllStandardOutput();

ui.textEdit->setText(QString(input));


app.exec();

return 0;
}

Corinzio
21st January 2009, 21:41
Try use QProcess::waitForFinished maybe your QProcess sysvProcess has not alreasy written anything to stdoutput when you call readAllStandardOutput().

GuL
11th February 2009, 19:08
try something like this:



QString prog = "/bin/bash";
QStringList arguments;
arguments << "-c" << "ls -hal";
QProcess* process = new QProcess(this);
process->start(prog , arguments);
process->waitForFinished();

QString tmp = process->readAll();
qDebug() << tmp;
ui.textEdit->setText(tmp);