WIndows和Qt获取exe运行文件的方法

Qt的方法:

#include <QApplication>

std::string getLogPath()
{
	//获取exe文件的路径,C:/a/b/DataManager.exe
	std::string exePath = qApp->applicationFilePath().toStdString();
	int i = exePath.rfind("/");
	//tmp=C:/a/b
	std::string tmp = exePath.substr(0,i);
	//log文件地址:C:/a/b/DataManager.log
	return tmp + "/DataManager.log";
}

WIndows的方法:

	string findSubPath(string path)
	{
		int i = path.rfind("\\");
		string tmp = path.substr(0,i);
		return tmp;
	}

	string getPath()
	{
		char path[MAX_PATH];
		GetModuleFileName(NULL, path, MAX_PATH);
		string tmp_path = findSubPath(path);
		return tmp_path;
	}

猜你喜欢

转载自blog.csdn.net/u012592062/article/details/80351279