There is an exe file its path is D: /a/b/test.exe Next to the exe file there is a folder with image / 1.jpeg files for example. There are also in the image folder and other folders with files. I want to get the path relative to exe ie through QFile I open the 1.jpeg file and I want to see its placement like this ./image/1.jpg, this is a relative path from the exe file, and not the absolute path D: / a / b / image / 1 .jpg as it takes me right now, right now. How to do it?
1 answer
#include <QCoreApplication> #include <QDir> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString appPath = "D:/programm"; QString imgPath = "D:/programm/image/1.jpg"; QDir dir(appPath); qDebug() << dir.relativeFilePath(imgPath); // image/1.jpg return a.exec(); } QString appPath = QCoreApplication::applicationDirPath();- Majestio- Alexander thanks relativeFilePath for what you need! - Disastricks
|