read multiple image from QFileDialog



  • 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=QString

    if 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,
    instead of

    imgOriginal = cv::imread(strFileName.toStdList());        // read image to imgOriginal
    

    use

    imgOriginalginal = cv::imread(strFileName.at(i).toStdString());        // read image to imgOriginal
    

  • Moderators

    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 the QStringList (= QList<QString>) to an std::list<QString>. But I guess you need a std::list<std::string>. That's why you have to iterate over the list and call QString::toStdString() for each list entry...



  • Thank you for the suggestion and explanation it is very helpful :D


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.