View Full Version : Very simple output task

8th April 2014, 14:40
Hi everyone,

I`m using QT 4.8 on a ubuntu 12.04 machine.

I`m at the end of finishing a little software. But now I cant get through a very simple task. I`m a newbie but I try hard :)

I just want to following linux command to be executed:

rhash -rH --sha1 --md5 /hashfolder >hashlist

Getting the output from rhash into the hashlist file.

QProcess rhasher;

QString rhash = "rhash";

rhasher.startDetached(QString("rhash -rH --sha1 --md5 /hashfolder/));

QString results = rhasher.readAllStandardOutput();

QFile file("/home/user/hashliste");

file.open(QIODevice::WriteOnly | QIODevice::Text);

QTextStream out(&file);

out << results;

std::cout << "make MD5 und SHA1 hashes" << std::endl;



I`m confusing myself right now. Hope you can help me out. Thanks

greetings Nand

8th April 2014, 16:01
startDetached is a static method, use QProcess::start() and connect to QProcess::readyReadStandardOutput signal to be notified when your process writes to stdout.

8th April 2014, 16:05
And allocate the process object on the heap.

8th April 2014, 16:15
ok thank you.

I try the best I can, dont know if I can do this.

8th April 2014, 16:17
Alternatively just use system() or popen() calls which are both blocking.

8th April 2014, 16:24
thanks for youre help. But I`m a bloody newbie. I dont know how to do this.

8th April 2014, 16:27
Open a terminal and type in "man popen" or search the internet.

8th April 2014, 16:38
FILE *fp;
int status;
char path[PATH_MAX];

fp = popen("rhash -rH --sha1 --md5 /home/user/ >hashlist", "r");
if (fp == NULL)
/* Handle error */;

while (fgets(path, PATH_MAX, fp) != NULL)
printf("%s", path);

status = pclose(fp);
if (status == -1) {

} else {


Maybe in a few days I`ve got it....

8th April 2014, 18:38
I would always use QProcess over low level C API.

If you really need it to be blocking use waitForFinished()


9th April 2014, 08:23
You are redirecting the output to a file so I don't know what you are expecting to receive on stdout of the process.