Qt how to open a file in current dir ? or what's wrong with this?

前端 未结 4 1172
遥遥无期
遥遥无期 2021-01-18 09:49

I\'m trying to open an xml file in the current location of the executable

        QString path = QDir::currentPath();
        path.append(\"/acc.xml\");
          


        
4条回答
  •  不思量自难忘°
    2021-01-18 10:11

    Check the returned value of QDir::currentPath(). I think when you run from Qt Creator, it returns the path where the project file (*.pro) is located. When you run from outside, you get path of the binary.

    Edit

    I never worked with Linux. However, you can try other functions/combinations from QDir:

    • QDir::current().path()
    • QDir::current().absolutePath()

    etc.

提交回复
热议问题