read multiple image from QFileDialog
Unsolved
General and Desktop
-
Hi all, I am trying to read multiple image and do some image processing with QFileDialog but receive the following error.
error: C2664: 'cv::Mat cv::imread(const cv::String &,int)' : cannot convert argument 1 from 'std::list<T,std::allocator<_Ty>>' to 'const cv::String &'
with [T=QStringif anyone knows what the error or solution is please advice :)
cv::Mat imgOriginal; // input image QStringList strFileName = QFileDialog::getOpenFileNames(); // bring up open file dialog if(!strFileName.isEmpty()) { for (int i =0;i<strFileName.count();i++) { ui->labelChosenFile->setText(strFileName.at(i)); imgOriginal = cv::imread(strFileName.toStdList()); // read image to imgOriginal } }
-
Hi!
You're program logic looks wrong.
if(!strFileName.isEmpty()) { for (int i =0;i<strFileName.count();i++) { ui->labelChosenFile->setText(strFileName.at(i)); imgOriginal = cv::imread(strFileName.at(i).toStdString()); // read image to imgOriginal } }
-
To add an explanationto the suggested fixes:
QList::toStdList()
converts theQStringList
(=QList<QString>
) to anstd::list<QString>
. But I guess you need astd::list<std::string>
. That's why you have to iterate over the list and callQString::toStdString()
for each list entry...