how to use void QDir::setPath(const QString &path) to assign a relative path?
-
hi
i got puzzle about this piece of code :```
QWidget(parent), ui(new Ui::Widget), musicDir(new QDir), musicFileInfo(new QList<QFileInfo>), mediaPlayer(new QMediaPlayer), mediaPlaylist(new QMediaPlaylist), imageDir(new QDir), imageFileInfo(new QList<QFileInfo>), imageTimer(new QTimer), imageRefreshTimer(new QTimer) { ui->setupUi(this); ui->image->setAlignment(Qt::AlignCenter); // musicDir->setPath("F:/project/WriteToMyDear-master/WriteToMyDear/music1"); musicDir->setPath("WriteToMyDear/music1"); music_path_exist = musicDir->exists();
i got "music_path_exist" false when i use relative path "musicDir->setPath("WriteToMyDear/music1");" and absolute path works fine.
can someone give some suggesstions?
thanks
-
From the documentation ( http://doc.qt.io/qt-5/qdir.html#setPath ):
Relative file names begin with a directory name or a file name and specify a path relative to the current directory.
And your current directory can be anything depending on where you start your application or if you switched it somewhere in your app.
-
hi
thanks for your help.
but i actually begin with a directory name:
and the " music1" directory is there:
and can you give me some suggestion?
thanks
-
hi
thanks for your help.
but i actually begin with a directory name:
and the " music1" directory is there:
and can you give me some suggestion?
thanks
@Mengmeng_Xiaoxiannv
Hi
Try
qDebug() << QDir::currentPath()
and see where current dir is.
On many platform it will be in the build folder where .exe is :)
And not the project folder.