Load Multiple Image

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


    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);


    any help is much appreciated.
    Thank you.

  • Moderators

  • @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()
       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) ;
                QImage image(str);
                label[i] = new QLabel(this);
                label[i]->setGeometry(100, 100*i, 50, 50);

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


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

  • @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'

Log in to reply