QStringList, how to access elements after getOpenFileNames
How do I access the individual strings in a QStringList that was created using getOpenFileNames?
QStringList fileNames;
fileNames = QFileDialog::getOpenFileNames(this,"Select File(s) to search","/home");
// If multiple files names were selected during getOpenFileNames, then how would I print (or access) each one selected?
// I have used getExistingDirectory to get a selected directory and then display it in the textEdit window.
// How can I do the same thing using getOpenFileNames?
QString DirName;
DirName = QFileDialog::getExistingDirectory(this,"Select Folder (Directory) to search in","/home");
ui.textEdit_SearchInFilesFolders->append(DirName);
Thanks,
Kevin
Re: QStringList, how to access elements after getOpenFileNames
Quote:
Originally Posted by
ketest
How do I access the individual strings in a QStringList that was created using getOpenFileNames?
QStringList fileNames;
fileNames = QFileDialog::getOpenFileNames(this,"Select File(s) to search","/home");
To assign the ith filename to fn:
You can write a straightforward for loop to iterate through the QStringList. The number of elements in the fileNames QStringList will be fileNames.size().
Bill.
Re: QStringList, how to access elements after getOpenFileNames
Or you can use
Code:
// do some useful stuff here
qDebug() << "Working on file " << s;
}
provided you have keywords enabled. The foreach functionality will be available as Q_FOREACH in any case.
Re: QStringList, how to access elements after getOpenFileNames
The .at was what I was missing.
Thanks,
Kevin
Re: QStringList, how to access elements after getOpenFileNames
Quote:
Originally Posted by
franz
Or you can use
Code:
// do some useful stuff here
qDebug() << "Working on file " << s;
}
provided you have keywords enabled. The foreach functionality will be available as Q_FOREACH in any case.
offtop, it's better to use const refs in foreach, you can take a look on this tests. :)