QStringList to QDir

  • I am getting error cannot convert from 'QStringList' to 'const QDir' -> problem is with *QDir dir(files)*and I don't know how to fix that... I need to get path of files added with QFileDialog and send them to playlist. But QDir can't read paths from QStringList...

    @void MainWindow::on_addSong_clicked()

    QString selectedFilter;
    QStringList files = QFileDialog::getOpenFileNames(
                                this, tr("QFileDialog::getOpenFileNames()"),
                                tr("MP3 Files (*.mp3)"),
    QDir dir(files);
    QList<QMediaContent> content;
    for(const QString& f:files)
        content.push_back(QUrl::fromLocalFile&#40;dir.path(&#41;+"/" + f&#41;&#41;;
        QFileInfo fi(f&#41;;
    if (files.count()) {
        openFilesPath = files[0];
        ui->label->setText(QString("[%1]").arg(files.join(", ")));


  • Moderators


    QDir is used to iterate over a directory. You can't use it to parse a QStringList.
    So to get the items from the QStringList you have to iterate it.
    @QStringList files = QFileDialog::getOpenFileNames(this, tr("QFileDialog::getOpenFileNames()"),QDir::rootPath());

    for(int i=0;i<files.count();i++)
        qDebug() << files.at(i);

    Also QFileDialog::getOpenFileNames returns the absolute path of the selected files.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.