Monday, January 17, 2011

Nokia Qt licensing (getting started on Windows 7 using Visual C++ 2008 Express edition)

( Addendum: Thanks to Gordon, New Zealand for pointing out that the recipe below won't work for 64-bit Windows 7 host - I had a 32-bit system. There, it seems, one must compile Qt from source. Check this out for assistance: Troubleshooting Visual Studio 2010 and Qt 4.7 integration )

Software should be simple. Software licensing should be simple. Software development should be simple.

Yeah, right.

Qt is a wonderful development tool from Trolltech and nowadays Nokia. But it seems to me they are doing their best to make starting using it difficult (I call this Symbian syndrome, it seems to be contagious).

About the Qt licensing

On their licensing page Nokia/Qt tries their best to make you feel like the commercial license really is what you need. Nope.

LGPL is what you need - also for development and sales of commercial software. Only if you must change the internals of Qt itself (who would?) and do not want to share those changes (why?) you should grab the commercial. At least I don't see any other reason. So - ignore the FUD and grab the LGPL.

Which download?

This is what turned me down on Symbian, years back. Fragmentation. So many packages that one cannot really know, which one to download.

Arguably, Qt is difficult for the packager. Some ten platforms. Different compilers. Cross compiling. But they indeed could be making it simpler.

This is the one you want (qt-win-opensource-4.7.1-vs2008.exe), for Windows 7 native development using the free Visual C++ 2008 Express edition (also the newer 2010 Express might work but I haven't tried).

Inconsistency warning

Nokia is saying that only gcc compiler is officially supported by the opensource installation package. This may be so but the free Visual C++ 2008 Express compiler works just splendidly. You really want to rather use the Microsoft compiler, since this means no need to install MingW and that stuff. In my opinion, Nokia/Qt could simply state the fact and "support" the Express compilers. Why not?

The opensource installer seems to be meant for both LGPL and GPL 3.0 licensing. So it implies when you start it. However, the click-through license being shown is only LGPL. This is a beauty spot - if I were Nokia/Qt, I'd call the package LGPL (instead of opensource) and simply keep the GPL 3.0 for the "generic all sources" package. Don't complicate things. No-one developing for Windows and with Visual C++ 2008 will use GPL, anyways. Give less blurry options. Be consistent.


These instructions are based on this, but updated.

1. Install Visual C++ 2008 Express (or 2010 Express)

Note: Though it is free, the Express version requires registration within the first 30 days. You must have a "Windows Live ID" for doing this.

2. Install the 'opensource' Qt 4.7.1 package

Installation is a breeze and now it seems problems are behind us. Run the demos at the end of the installation - they give a good picture of what Qt can do.

3. Creating your own project

( Now, I'm not sure if all this works right after installation. If not, do the next step - configure and compile Qt - first. )

Add the Qt binaries folder to the PATH unless it's already there (wasn't for me - why wouldn't the installer have done this?)

    Start > Control panel > search: environment > Edit account's environment variables (or something like that)

PATH C:\Qt\4.7.1\bin

Open a "Visual Studio 2008 Command Prompt" ( Start > Programs > ... > Visual Studio Tools > ... ). This is normal Windows command prompt with some environment variables set so one can compile stuff (see with 'set' command).

Create an empty folder (MyDemo) and a source file (main.cpp) in it:

   mkdir MyDemo
cd MyDemo
( create main.cpp with a text editor, see contents i.e. from here )
qmake -project




   cd debug

Success? If not, give a comment on this blog.

4. Configuring and recompiling Qt itself

Open the "Visual Studio 2008 Command Prompt"

cd \Qt\4.7.1
configure --help

That shows all the different configuration options.

Try something like this (all in one line):

-platform win32-msvc2008 
-no-style-motif -no-style-cde

configure will ask you for the license. Confirm open source by 'y'.

Running configure took around 20 minutes. Make some coffee...


Running nmake took around 2 hours. Watch some tv...

To clear an earlier configuration:

   nmake confclean

What about Qt Creator?

The above installation brings the command line tools and the Qt Designer (the UI editing tool) to your usage.

It does not, however, bring an IDE.

Qt Creator is an IDE for Qt. The current name of the Windows installer is qt-creator-win-opensource-2.0.1.exe. Download.

Another IDE option is to integrate Qt development with Visual C++, using that as the IDE. This is done using the Qt Visual Studio Add-in (qt-vs-addin-1.1.7.exe). Visual C++ 2008 Express does not support add-ins, however, which leaves us either to work on the command prompt (quite fine) or use Qt Creator.

Note: You can uncheck the "MinGW runtime development tools" option when installing Qt Creator (since we're not using MinGW).

Note: If using Qt Creator with projects on network drives (or i.e. shared host disk of VMWare as I do), use drive letter mappings (s.a. G:) instead of the long path names (s.a. \\vmware-host\Shared Folders\...). It may be the space in the path name or it may be the \\ style but I didn't get projects to run that way. Drive mapping helps (create those in main level of 'Computer' view of the Windows file manager).

Debugging with Qt Creator

Qt Creator needs a CDB console debugger in order to allow you to single step and debug your code. This is a separate download from Microsoft, under the name Debugging Tools for Windows. The actual installer is named winsdk_web.exe (Windows 7 SDK etc.).

You only need to have the "Debugging Tools for Window" option checked in the above installer. It may give some warnings about only having the "client" parts of .NET something 4 installed. This is okay, proceed.

Once the stuff is installed, restart Qt Creator and it should now be able to debug (add a breakpoint, try single step, look for variable values). Voila!

( It does say about "Debug helper" not being rightly set up or needing a new compile. Maybe, if we had started with CDB being there Qt would have gotten all the stuff right. Or maybe it's something else. Anyways, it seems Debug helper is not so valuable. We can still see the contents of all regular C++ constructs just fine. )

Finally there

It shouldn't be this hard.

But now that Qt and all the pieces are in place, Qt Creator is actually feeling like a very nice IDE. And Qt itself is awsome, that I know anyways (otherwise I might have lost hope in the midst of this). The official response of Qt people would surely be "either use MinGW or get the real Visual C++ software (and use the plugin)." Well, I don't want to. I have good experience of using VC++ Express versions and see no reason they shouldn't/couldn't be supported by Qt.

What Nokia/Qt could do, in my opinion, is to make a dynamic webpage (using JavaScript and CSS) that takes one through the whole installation routine, on a one single page. The page would have road junctions along it, asking you for something (s.a. which environment you want to build on and what to target, what compiler to use, license etc.) But all this would happen on the one single page. Then at the end you would get a list of *all* required downloads in the order they should be installed. That would be dead easy (both for them and for the page visitors). Now they seem to be going for "one package installs all" (most likely because managers prefer that way). This is not necessarily best for developers, since we want to have each thing only once, and understand how the parts fit together.

To get a feel of what the current situation is, look here:

At footer of all the tabs:
- 4 Qt Creator binaries links
- 1 Qt Creator source link
- 1 Visual Studio Add-in link
- 1 Nokia SDK link

LGPL tab:
- 5 "Complete development environment" links
- 7 "Qt libraries" links

Commercial tab:
- no links (just forms)

That page is the main cause of the headache. Don't use tabs on it - make the flow from up to down. Way less information-like links, or make them visually separate from the download links. USABILITY, PLEASE!

None of this is clearly expressed on the Nokia/Qt website, leading to unnecessary downloads and time lost trying to figure out what works and what does not. This is why this blog entry was created.

No comments: