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. Load images from a directory into QList<QPixmap>

Load images from a directory into QList<QPixmap>

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.3k 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.
  • F Offline
    F Offline
    franad
    wrote on last edited by
    #1

    Hey everyone,

    i need to load some images from a directory into my programm. I'm able to get a QList<QStrings> with the filenames of my Images, but i need them as Pixmaps. Any idea how to solve this?

    Thanks a lot!

    raven-worxR 1 Reply Last reply
    0
    • F franad

      Hey everyone,

      i need to load some images from a directory into my programm. I'm able to get a QList<QStrings> with the filenames of my Images, but i need them as Pixmaps. Any idea how to solve this?

      Thanks a lot!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @franad

      QList>QPixmap> pixmaps;
      for( int i = 0; i < fileNames; ++i )
          pixmaps  << QPixmap(fileNames.at(i));
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • F Offline
        F Offline
        franad
        wrote on last edited by
        #3

        @raven-worx, thanks a lot for your help!
        unfortunately it seems like I've got any mistake anyway.

        Here's the actual code:

        QDir directory("C:/Users/.../references");
        QList<QString> examples << "*.png";
        QList<QString> exlist = directory.entryList(examples);
        for (int z = 0; z < exlist.size(); z++) {
                QList<QPixmap>exampleList << QPixmap(exlist.at(z));
        }
        ui->exampleLabel->setPixmap(exampleList.at(3));
        ui->exampleLabel->show();
        
        

        Last two lines should show the Image with Index 3 at my label, but it doesn't work

        raven-worxR 1 Reply Last reply
        0
        • F franad

          @raven-worx, thanks a lot for your help!
          unfortunately it seems like I've got any mistake anyway.

          Here's the actual code:

          QDir directory("C:/Users/.../references");
          QList<QString> examples << "*.png";
          QList<QString> exlist = directory.entryList(examples);
          for (int z = 0; z < exlist.size(); z++) {
                  QList<QPixmap>exampleList << QPixmap(exlist.at(z));
          }
          ui->exampleLabel->setPixmap(exampleList.at(3));
          ui->exampleLabel->show();
          
          

          Last two lines should show the Image with Index 3 at my label, but it doesn't work

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @franad
          I dont think that QDir::entryList() returns absolute paths but only the names?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2
          • F Offline
            F Offline
            franad
            wrote on last edited by
            #5

            @raven-worx
            when I do something like

            examplePixmap.load("references/"+exlist.at(0));
            
            

            it works. "Works" means that I can show up my examplePixmap in a Label.
            But if there is any other posibility to get the absolute paths of my files I would be fine with that.
            Unfortunately I'm pretty new to qt...

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're passing the path to QDir so why don't you use this? QDir also has e.g. QDir::absoulteFilePath() - http://doc.qt.io/qt-5/qdir.html#absoluteFilePath

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2
              • F Offline
                F Offline
                franad
                wrote on last edited by
                #7

                @Christian-Ehrlicher

                thank you for your help! Could you please precise your hint a little bit?

                1 Reply Last reply
                0
                • Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @franad said in Load images from a directory into QList<QPixmap>:

                  for (const QString &fileName : exlist)
                      exampleList.push_back(QPixmap(directory.absoluteFilePath(fileName));
                  

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1
                  • F Offline
                    F Offline
                    franad
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher

                    Thanks a lot! Everythings seems fine now. Thank you

                    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