Have you also discovered all the new fancy C++11 stuff? So far I’ve used only the new flavor of auto and some ranged for-loops, but already those I think are great improvements.
If you try them in your Qt app however, you most likely will get a compiler error. Easily fixed, add a command to the .pro file in your project. Here’s an example, before editing:
... HEADERS += mainwindow.h FORMS += mainwindow.ui
At the end insert a new line, like this:
... HEADERS += mainwindow.h FORMS += mainwindow.ui CONFIG += c++11
That should suffice to make your compiler happy. Note: this is applicable for MinGW on Windows, and for Mac and Linux systems. Also, for Macs, make sure it is written
"c++11" and not
"C++11", otherwise you’ll get this error:
For Visual Studio 2010 however, that CONFIG statement is a dud, it will not magically make VS2010 understand something it wasn’t built to understand. You’ll have to upgrade to VS2012 or VS2013. Also for those later compilers C++11 is the default setting so that CONFIG statement is immaterial. I usually include it anyway, in case I’m targeting something else than Windows later on.
(Note also that for this above to work, you need to use Qt 5.2 or later. Earlier versions required different settings for C++11 for Windows, Mac or Linux.)
Next up: deployment to other PCs.
Hi (first post: the reason I started this blog was all the small details re. Qt installation, deployment etc. Had some scattered notes, so I thought why not put them on the web, that way I’ll find them for sure next time they’re needed.)
The really outstanding feature of Qt: you can have a reasonable complex program written in C++ running fine on Windows, then recompile the code in Qt for the Mac or Linux and chances are pretty high it’ll behave the same!
Let’s start by looking at triple-installing Qt (version 5.2.1 when I write this):
- Windows: You will need a copy of Visual Studio, or opt for the open source MinGW compiler that you can download and install together with Qt. MinGW is a good choice for portability and cost, you’ll have no problem with Qt or deploying Qt apps on various versions of Windows. For me though, MinGW is less ideal, because most Windows stuff are built using Visual Studio. For example, Qt’s IDE QtCreator is built with Visual Studio 2010. That means if I want to use MinGW for building QtCreator plugins/DLLs, I’ll first have to rebuild and switch to a new MinGW-flavored version.
So, 2 major versions of Visual Studio are supported, VS2010 and VS2012. A bit of hacking should allow you to use VS2013 (I haven’t tried it myself) Microsoft’s current version, as well.
For me, VS2010 is also less ideal. I’ve grown used to some of the new fancy C++11 features like the auto keyword, and VS2010 just spits those out. So choosing VS2012 is a no-brainer. Only one problem: apps built with VS2012 are trickier to deploy to Windows XP, more on that later.
Edit: When you run QtCreator on Windows XP or Windows 2003 server, the start screen is not properly refreshed (shows artifacts). One way to get around that is to disable the welcome plugin: select the Help menu, About Plugins, locate the Welcome plugin and deselect the Load tick box for it.
- Mac: Here you will need a recent download of Xcode and the command line tools for it.
Building apps for your Mac desktop works well, but when deploying your app to other machines, you are left somewhat in the cold; the app bundle contains DLL references with the same explicit paths to Qt’s frameworks/DLLs as on your development Mac. So this means Qt apps can only be run on other Macs with an identical installation of Qt? No, there are a couple of ways around this of course, we’ll look at that in a later blog post.
- Linux: I’ve tried Qt on both Ubuntu and Debian, in both of those you’ll first need to download the GCC compiler (the C++ flavored one):
sudo apt-get install g++
Now if linking fails:
you need to download the OpenGL utility library as well:
sudo apt-get install libglu1-mesa-dev
Building apps works well, but also on these systems there can be trouble ahead when trying to deploy to other Linux machines without Qt installed. Ubuntu though (not Debian) comes with some Qt DLLs preinstalled so a simple app will run directly. However those DLLs are from version 5.02 of Qt (that’s for Ubuntu 13.10) so if you are using some new 5.2.x feature you might be better off by deploying current DLLs. We’ll look at that later as well.
At this point you should be able to write and run a simple Hello World test program. Next post we’ll look at how to enable C++11 features like auto, range-based for-loops etc.