Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wxwidgets getting application path

Tags:

wxwidgets

My config:

  • wxWidgets version: 3.0.1
  • Codeblocks version: 13.12 64bit
  • Compiler: gnu gcc 4.8.2
  • platform/OS: Linux 64bit Ubuntu 14.04.1 LTS

I can't seem to use the UseAppInfo correctly. I don't want the app name in the path, just the path of the executable. I am trying this:

wxStandardPaths::Get().UseAppInfo(wxStandardPaths::AppInfo_None);
wxString strExe = wxStandardPaths::Get().GetExecutablePath();

strExe contains the full path and the executable name, despite the option AppInfo_None in UseAppInfo in the line above it. I am aware that I am getting an instance from a Get() which doesn't seem to be carried over in the next line.. The doc says to use wxStandardPaths through wxStandardPaths::Get().

I did tried the following as well, which doesn't work either (surprisingly it doesn't crash and does give me the full path including app name):

wxStandardPaths &path = wxStandardPaths::Get();
path.UseAppInfo(wxStandardPaths::AppInfo_None);
wxString strExe = path.GetExecutablePath();

Any suggestions?

like image 580
mimosa Avatar asked Jan 09 '23 20:01

mimosa


1 Answers

wxGetCwd() is not guaranteed to give the path to the application. In fact, you can change that path while the application is running using wxSetWorkingDirectory.

The best method I have found to get the path to the application is to use GetExecutablePath and use wxFileName to remove the application name.

//need to include <wx/filename.h> and <wx/stdpaths.h>

wxFileName f(wxStandardPaths::Get().GetExecutablePath());
wxString appPath(f.GetPath());
like image 61
ioums Avatar answered Feb 04 '23 11:02

ioums