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()"), openFilesPath, tr("MP3 Files (*.mp3)"), &selectedFilter ); QDir dir(files); QList<QMediaContent> content; for(const QString& f:files) { content.push_back(QUrl::fromLocalFile(dir.path()+"/" + f)); QFileInfo fi(f); ui->listWidget1->addItem(fi.fileName()); } playlist->addMedia(content); if (files.count()) { openFilesPath = files[0]; ui->label->setText(QString("[%1]").arg(files.join(", "))); }
}@
-
Hi,
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.
Eg.
@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.