Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Load Multiple Image
QtWS25 Last Chance

Load Multiple Image

Scheduled Pinned Locked Moved Solved Brainstorm
6 Posts 3 Posters 4.4k Views
  • 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.
  • HashTagJFH Offline
    HashTagJFH Offline
    HashTagJF
    wrote on last edited by
    #1

    Good day everyone,
    I'd like to create a project using qt that loads multiple image/pictures. I already know how to load a single image but I'm not sure how to I could open multiple pictures.

    Here's the code I use when loading a single image.

    mainwindow.cpp

    void MainWindow::on_LoadImage_clicked()
    {
    QString filename = QFileDialog::getOpenFileName(this,tr("Open File"),"",tr("JPEG (.jpg .jpeg);;PNG (.png);;ZIP (.zip)" ));

    if (!filename.isEmpty()){
        QImage image(filename);
         ui->label->setPixmap(QPixmap::fromImage(image));
    }
    

    }

    any help is much appreciated.
    Thank you.

    raven-worxR 1 Reply Last reply
    0
    • HashTagJFH HashTagJF

      Good day everyone,
      I'd like to create a project using qt that loads multiple image/pictures. I already know how to load a single image but I'm not sure how to I could open multiple pictures.

      Here's the code I use when loading a single image.

      mainwindow.cpp

      void MainWindow::on_LoadImage_clicked()
      {
      QString filename = QFileDialog::getOpenFileName(this,tr("Open File"),"",tr("JPEG (.jpg .jpeg);;PNG (.png);;ZIP (.zip)" ));

      if (!filename.isEmpty()){
          QImage image(filename);
           ui->label->setPixmap(QPixmap::fromImage(image));
      }
      

      }

      any help is much appreciated.
      Thank you.

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

      @HashTagJF
      QFileDialog::getOpenFileNames()

      --- 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
      1
      • V Offline
        V Offline
        Vicky Sharma
        wrote on last edited by VRonin
        #3

        @HashTagJF

        I tried your example and make some changes as per need so just try it once and get back if any issue.

        And one more thing, to obtain result as per your need we need array of label, so ignore ui->label and created oneself as like below code.

        void MainWindow::on_LoadImage_clicked()
        {
           qDebug()<<"clicked.....";
           QStringList filename = QFileDialog::getOpenFileNames(this,tr("Open File"),
                                                             tr("All Files (*.jpg *.jpg *.png *.zip)"));
        
           if (!filename.isEmpty()){
               for(int i=0; i<filename.length(); i++){
                   QString str = filename.at(i) ;
                   qDebug()<<"str========>>>>>"<<str;
                    QImage image(str);
                    label[i] = new QLabel(this);
                    label[i]->setGeometry(100, 100*i, 50, 50);
                    label[i]->setPixmap(QPixmap::fromImage(image));
                    label[i]->show();
               }
           }
        }
        
        HashTagJFH 2 Replies Last reply
        0
        • V Vicky Sharma

          @HashTagJF

          I tried your example and make some changes as per need so just try it once and get back if any issue.

          And one more thing, to obtain result as per your need we need array of label, so ignore ui->label and created oneself as like below code.

          void MainWindow::on_LoadImage_clicked()
          {
             qDebug()<<"clicked.....";
             QStringList filename = QFileDialog::getOpenFileNames(this,tr("Open File"),
                                                               tr("All Files (*.jpg *.jpg *.png *.zip)"));
          
             if (!filename.isEmpty()){
                 for(int i=0; i<filename.length(); i++){
                     QString str = filename.at(i) ;
                     qDebug()<<"str========>>>>>"<<str;
                      QImage image(str);
                      label[i] = new QLabel(this);
                      label[i]->setGeometry(100, 100*i, 50, 50);
                      label[i]->setPixmap(QPixmap::fromImage(image));
                      label[i]->show();
                 }
             }
          }
          
          HashTagJFH Offline
          HashTagJFH Offline
          HashTagJF
          wrote on last edited by
          #4

          @Vicky-Sharma Hi thank you so much for your answer. However, I'm having some errors with the code that you have given me.

          0_1479948362743_upload-07005fbb-ce1a-4c6f-ae78-b813f1526a7c

          1 Reply Last reply
          0
          • V Vicky Sharma

            @HashTagJF

            I tried your example and make some changes as per need so just try it once and get back if any issue.

            And one more thing, to obtain result as per your need we need array of label, so ignore ui->label and created oneself as like below code.

            void MainWindow::on_LoadImage_clicked()
            {
               qDebug()<<"clicked.....";
               QStringList filename = QFileDialog::getOpenFileNames(this,tr("Open File"),
                                                                 tr("All Files (*.jpg *.jpg *.png *.zip)"));
            
               if (!filename.isEmpty()){
                   for(int i=0; i<filename.length(); i++){
                       QString str = filename.at(i) ;
                       qDebug()<<"str========>>>>>"<<str;
                        QImage image(str);
                        label[i] = new QLabel(this);
                        label[i]->setGeometry(100, 100*i, 50, 50);
                        label[i]->setPixmap(QPixmap::fromImage(image));
                        label[i]->show();
                   }
               }
            }
            
            HashTagJFH Offline
            HashTagJFH Offline
            HashTagJF
            wrote on last edited by HashTagJF
            #5

            @Vicky-Sharma I found the error..
            I need to add ==== QLabel *label[10]; === in the header file. Thank you so much for your help. But I could only add 10 pictures so this solution is still temporary.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Vicky Sharma
              wrote on last edited by
              #6

              @HashTagJF
              I think you didn't check this ' QLabel *label[10];'

              Because you fixed it limit of array upto 10 that'swhy it's obtaining only 10, so just increase its limit you will find your answer.

              And if its solved your problem then make it 'solved'

              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