Re: Read stdout to a widget
Please take a look at the documentation: https://doc.qt.io/qt-5/qprocess.html#details
There you will find how to read from stdout
Re: Read stdout to a widget
Thx, i'll check that.
Which widget would be the best to show the results and make each line clickable for the user?
Re: Read stdout to a widget
Quote:
make each line clickable for the user?
And what is supposed to happen when the user clicks on a line?
I would probably start by looking at QListWidget or QTableWidget depending on whether you want one or two columns in your display.
Re: Read stdout to a widget
Quote:
Originally Posted by
d_stranz
And what is supposed to happen when the user clicks on a line?
I would probably start by looking at
QListWidget or
QTableWidget depending on whether you want one or two columns in your display.
The aim is to click on the found frequency in the list and then to tune to the station.
Trying to build the example for QProcess but getting an error:
Code:
void DAB_FM::on_btnScan_clicked()
{
//DAB
if (ui->dabButton->isChecked()){
QString program
= "/opt/bin/mediaclient";
arguments << "--scandabfrequencies" << "/dev/dab0";
myProcess->start(program, arguments);
}
}
Warning says: /home/ubuntu/DAB_FM/dab_fm.cpp:98: Warnung: variable 'parent' is uninitialized when used here
When clicking on scan, the app crashes.
Edit:
From some tutorials i decided to use the ListWidget. The question for me is, how can I read the stdout from QProcess::execute and pass the returned stdout to the ListWidget.
1 Attachment(s)
Re: Read stdout to a widget
Ok, so far I'm able to read the output now, but the result is shown as one item in the widget. I'd like to have each line of the output as one item.
Code:
void DAB_FM::on_btnScan_clicked()
{
//DAB
if (ui->dabButton->isChecked()){
process.start("/opt/bin/mediaclient --scandabfrequencies /dev/dab0");
process.waitForFinished();
QByteArray output
(process.
readAllStandardOutput());
ui->listScan->addItem(output);
}
//FM
if (ui->fmButton->isChecked()){
process.start("/opt/bin/mediaclient --scanfmfrequencies /dev/radio0");
process.waitForFinished();
QByteArray output
(process.
readAllStandardOutput());
ui->listScan->addItem(output);
}
}
Result for FM Scan:
Attachment 13400
Re: Read stdout to a widget
Quote:
QByteArray output(process.readAllStandardOutput());
ui->listScan->addItem(output);
Well if you are reading it all into a single QByteArray, and passing that entire array to addItem(), the list widget is doing exactly what you told it to - add a single item.
Most of this basic stuff is covered in the Qt documentation and the Qt examples and tutorials.
Look at QString and its constructor that takes a QByteArray as input, QString::split(), QStringList, and QListWidget::addItems(), QListWidget::itemClicked() (or itemDoubleClicked() depending on the behavior you want).