2

I am writing an avrdude helper program that facilitates calling a few command-line arguments. When issuing avrdude commands in the console a series of output results will be displayed on the screen. Is there anyway to grab that output and display it in a GUI window (using Qt, if that matters)?

I figured I could take the output and redirect it to a file (avrdude -args > textFile.txt) that could be read and displayed on the screen at runtime if nothing else.

Just wondering if there are any other alternatives to capturing this output.

4

2 回答 2

3

我认为关键类是QProcessQLabel或一些类似的 GUI 小部件,如下所示:

QProcess avrDudeProcess;
avrDudeProcess.setProcessChannelMode(QProcess::MergedChannels);
avrDudeProcess.start("avrdude", optionList);
if (!avrDudeProcess.waitForStarted())
    return false;

if (!avrDudeProcess.waitForFinished())
    return false;

QByteArray output = avrDudeProcess.readAll();
myLabel.setText(output);
于 2014-05-24T02:43:38.210 回答
2

也许,这就是你要找的。

http://linux.die.net/man/3/popen

这是一个例子:

/* First open the command for reading. */
FILE * file = popen("/bin/ls /etc/", "r");

char output[100];
/* Read the output line by line */
while (fgets(output, 100, file) != NULL) 
{
    printf("%s", output); /* show the result */
}

/* close */
pclose(file);

祝你好运!

于 2014-05-24T02:07:10.747 回答