Garmaine Staff asked 2 years ago

just want to put it out there that I am a beginner at C++. I'm trying get all the elements in my QListView and insert them into a Vector.

This is my loaddataset function which loads the files from a folder into the QListView:

void MainWindow::on_actionLoad_Dataset_triggered()
    QString sPath = QFileDialog::getExistingDirectory(this, tr("Choose catalog"), ".", QFileDialog::ReadOnly);
    QStringList filter;
    filter << QLatin1String("*.png");
    filter << QLatin1String("*.jpeg");
    filter << QLatin1String("*.jpg");
    filter << QLatin1String("*.gif");
    filter << QLatin1String("*.raw");
    filemodel -> setNameFilters(filter);

    ui -> imgList -> setRootIndex(filemodel -> setRootPath(sPath)); 

This is my QList function which then takes the file that the user clicks on and loads it onto a PixMap:

void MainWindow::on_imgList_clicked(const QModelIndex &index)
    imgNames = {};

    QString sPath = filemodel -> fileInfo(index).path();

    QString paths = filemodel -> fileInfo(index).fileName();

    //this kind of does it but instead of pushing them all it only pushes the ones that the user has clicked on instead of all

    map -> filename = filemodel -> filePath(index);

    map -> loadImage(scene);
    scene -> addItem(map);