Launching URL - Cross Platform (C++) - c++

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 Qt or something like that. Qt has a nice class called QDesktopServices which you can use to do it:
QDesktopServices::openUrl(QUrl("http://google.com", QUrl::TolerantMode));
According to the documentation:
Opens the given url in the appropriate Web browser for the user's
desktop environment, and returns true if successful; otherwise returns
false.
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 ShellExecute function, 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.

Related

Website screen capture from native application

I have a native C++ application built using using OpenGL (and openFrameworks as well in some core classes). I have been looking for a way to programatically take the screenshot of a website from this desktop application that is to happen on some interaction by the user and save it in a certain path on the computer.
I am fine with installing a separate application to issue commands to it somehow, a command line program, including a small API or library etc. but I have to stick to Windows for this purpose.
I won't be able to include another full framework such as Qt for this purpose (which I believe gives the ability to take a screenshot from native application). I found some solutions for mac and linux but couldn't find anything for windows:
webkit2png : http://www.paulhammond.org/webkit2png/
khtml2png : http://khtml2png.sourceforge.net etc.

Cross Platform Browser Detection

Can anyone help me out, I need a cross platform way to detect if browsers are installed e.g. Is Firefox installed, Is Safari installed etc.
I am using wxWidgets for my GUI libary if this helps.
I can check the registry on windows but am unsure on how find out browsers for Linux and Mac. Would prefer one clean cross platform way rather than several
If(windows)
then search registry
If (Mac)
then do something else
etc.
Thanks
What's wrong with http://docs.wxwidgets.org/2.6.3/wx_miscellany.html#wxlaunchdefaultbrowser?
And why not using several ways of detection? This functionality could then be implemented in wxWidgets itself. After all, wxWidgets does exactly this and just abstracts it away using function with platform specifics hidden behind.

Easy way to cross-compile a Qt application using Qt Creator?

I'm very new to this C++ and Qt Creator thing, I'm using Qt Creator in Mac OS X.
Is there an easy way to compile for Windows and Linux platform also?
The current way I'm doing is copying the source file to a Windows machine (with Qt) and compile it, which takes a lot of time.
Is there a command or something that can get all 3 executables at once?
It's not supported out of the box and you might end up messing between the different flavours
I strongly suggest, for such a goal:
- to use either centralised (svn) or distributed (git, hg) SCM
- to use continuus integration with 3 agents, each one in a different platform (can be VM or physical computer). You can use hudson or cruise control
This way:
- you develop locally, on whatever platform you prefer
- you push / commit / submit your changes
- the buildbox compiles on all platforms (while you can still work on the next feature)
- ideally, you run your unit tests as well
- once all builds on all platforms are finished, you got a status and a build on all targets
This is fairly useful when wanting to deal with more than one version of Qt or compiler : the return value is definitely worth the time invested in the setup (and it scales well)
It is far from trivial, and Trolltech didn't like the idea (by making it harder than it should be).
There is Cross compiling Qt/Win Apps on Linux on the Internet which will help (only directories might be different for Mac, commands should be the same).
After you have cross-compiled, you'll need to create a shortcut to Qt Creator with a custom PATH that has your cross-compiler directory prepended to the rest of the PATH. That way you can ensure it is used. This is not recommended though.
Why not just use a properly set up VM?

Desktop Development Environment that Compiles to Linux, Mac OS, and Windows

is there any development environments that allow you to have one code base that can compile to Linux, Mac OS, and Windows versions without much tweaking? I know this is like asking for where the Holy Grail is burred, but maybe such a thing exists. Thanks.
This is achieved through a number of mechanisms, the most prominent being build systems and specific versions of code for certain systems. What you do is write your code such that, if it requires an operating system API, it calls a specific function. By example, I might use MyThreadFunction(). Now, when I build under Linux I get a linux specific version of this MyThreadFunction() that calls pthread_create() whereas the windows version calls CreateThread(). The appropriate includes are also included in these specific platform-files.
The other thing to do is to use libraries that provide consistent interfaces across platforms. wxWidgets is one such platform for writing desktop apps, as is Qt and GTK+ for that matter. Any libraries you use it is worth trying to find a cross-platform implementation. Someone will undoubtedly mention Boost at some point here. The other system I know if is the Apache Portable Runtime (APR) that provides a whole array of things to allow httpd to run on Windows/Linux/Mac.
This way, your core code-base is platform-agnostic - your build system includes the system specific bits and your code base links them together.
Now, can you do this from one desktop? I know you can compile for Windows from Linux and so probably for Mac OS X from Linux, but I doubt if you can do it from Windows-Linux. In any case, you need to test what you've built on each platform so my advice would be to run virtual machines (see vmware/virtualbox).
Finally, editors/environments: use whatever suits you. I use either Eclipse/GVim on Linux and Visual Studio on Windows - VS is my "Windows build system".
Maybe something like CodeBlocks?
Qt is a good library/API/framework for doing this in C++, and Qt Creator is a very pleasant IDE for it.
I've heard this is possible. Your compiler would need to support this. The only one that I know that does is GCC but it obviously requires a special configuration. I, however, have never used this feature. I've only seen that it exists.
What you are looking for is called "Cross Compiling"

Cross platform c++ with libcurl

I am a perl developer that has never went into the client side programming of things. I'd like to think that I'm a pretty good developer, except I know that my severe lack of knowledge of the way desktop programming really takes away from my credibility.
That said, I really want to get into doing some desktop applications.
I want to try to develop a simple application that will connect to my server and grab an rss feed, then display it in the console. My plan of attack is to use libcurl (and curlpp) to grab the feed (I'd also like to do more curl stuff in the future). But I want to be able to run this small program on linux, windows, and mac because I want to understand developing cross platform.
So here is the question (and I know it is extremely noobish): How do I write c++ code that will use libcurl and curlpp, and will work on the 3 major OSes? The main thing I don't understand is if I have to compile libcurl and curlpp, then how does it work when trying to take it over to the other platforms?
You need to write the code portably - basically make it a console application. You then transfer the source code (not the exe) to the other platforms and compile it there and link with the version of llibcurl on each specific platform.
Neil is right, but using a framework will make your life easier. Try QT it is very nice. It has a cross platform http API, and integrates curl.
I'd recommend Qt4 as well, I've wrote a small'ish tutorial on how to setup a windows gcc compiler on linux and compile Qt4/OpenSSL with it for windows, hope that helps.
http://www.limitlessfx.com/mingw-openssl-qt4-for-windows-on-linux.html
You can easily adapt that tutorial to compiling libcurl instead of just moving to Qt4.