Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. read multiple image from QFileDialog
Forum Updated to NodeBB v4.3 + New Features

read multiple image from QFileDialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • xenaX Offline
    xenaX Offline
    xena
    wrote on last edited by
    #1

    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
            }
        }
    
    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gerd
      wrote on last edited by
      #2

      Hi,
      instead of

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

      use

      imgOriginalginal = cv::imread(strFileName.at(i).toStdString());        // read image to imgOriginal
      
      1 Reply Last reply
      3
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
            }
        }
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        5
        • miclandM Offline
          miclandM Offline
          micland
          wrote on last edited by
          #4

          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...

          1 Reply Last reply
          3
          • xenaX Offline
            xenaX Offline
            xena
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved