Skip to content

Instantly share code, notes, and snippets.

@jniemann66
Created April 7, 2016 06:43
Show Gist options
  • Save jniemann66/8ad5c55d19bf8b8660c4e7b4ab7e7d4a to your computer and use it in GitHub Desktop.
Save jniemann66/8ad5c55d19bf8b8660c4e7b4ab7e7d4a to your computer and use it in GitHub Desktop.
Qt: populating QCombox items using std output from external process
// Launch external process, and populate QComboBox using output from the process:
void MainWindow::PopulateBitFormats(const QString& fileName)
{
QProcess ConverterQuery;
ui->BitDepthCombo->clear();
int extidx = fileName.lastIndexOf(".");
if(extidx > -1){
QString ext = fileName.right(fileName.length()-extidx-1); // get file extension from filename
ConverterQuery.start(ConverterPath, QStringList() << "--listsubformats" << ext); // ask converter for a list of subformats for the given file extension
if (!ConverterQuery.waitForFinished())
return;
ConverterQuery.setReadChannel(QProcess::StandardOutput);
while(ConverterQuery.canReadLine()){
QString line = QString::fromLocal8Bit(ConverterQuery.readLine());
ui->BitDepthCombo->addItem(line.simplified());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment