Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to use void QDir::setPath(const QString &path) to assign a relative path?

how to use void QDir::setPath(const QString &path) to assign a relative path?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 694 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mengmeng_Xiaoxiannv
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • M Offline
        M Offline
        Mengmeng_Xiaoxiannv
        wrote on last edited by
        #3

        hi

        thanks for your help.

        but i actually begin with a directory name:
        0_1534666842633_无标题.png

        and the " music1" directory is there:
        0_1534666991570_捕获.PNG

        and can you give me some suggestion?

        thanks

        mrjjM 1 Reply Last reply
        0
        • M Mengmeng_Xiaoxiannv

          hi

          thanks for your help.

          but i actually begin with a directory name:
          0_1534666842633_无标题.png

          and the " music1" directory is there:
          0_1534666991570_捕获.PNG

          and can you give me some suggestion?

          thanks

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

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

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved