I am not sure if this is possible, but I am trying to open a URL in the users default browser in C++. I would just use ‘ShellExecute’, but I am trying to make it cross platform. Anyone know any ways that this is possible, if it is?
By cross platform I mean the 3:
- Linux
- Windows
- Mac
I’ve literally Google search for sooo long, and found nothing. Thanks for any help 🙂
Your best bet is to use a cross platform library like
Qtor something like that. Qt has a nice class calledQDesktopServiceswhich you can use to do it:According to the documentation:
Do note that this will add an dependency on Qt for all your platforms for what might be a very trivial task. It is best that you use custom code for each platform and set compiler directives to see which operating system you are on and run the browser launching code according to that.
Like, if it is being compiled on windows, you could just compile
ShellExecutefunction, if it is being run on Linux, then depending on the desktop environment you could run the appropriate command.But, if you are really making a cross platform application, a dependency like Qt would not be bad as it will help with a lot of cross-platform stuff (like keeping an icon in the system tray, multimedia playback etc.).
Without a library, there is no standard-C++ way to do it that will run on all platforms.