I'm trying to open an xml file in the current location of the executable
QString path = QDir::currentPath();
path.append("/acc.xml");
QFile file(path);
if(!file.open(QIODevice::ReadOnly))
{
insertItem("IO ERR");
}
When I run it from Qt creator, everything works. currentPath()
returns the path to the executable's folder
When I go to project-build-desktop/
folder and try to run it manually currentPath()
returns /home/user/Documents
EDIT
also tried with same results:
Qt::current().path();
Qt::current().absolutePath();
Try to use QCoreApplication::applicationDirPath() instead of QDir::currentPath().
For details see http://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath
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
:
etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With