Nokia places Qt under LGPL License – Sweet!

I have been a big fan of the Trolltech Qt Framework for a number of years. It is a fantastic way to build high quality cross-platform desktop applications in C++. For the past six years it seems like every project I work on has included a rich desktop GUI application of some sort. Each time this need would arise I would start the process of selling the idea of using the Qt Framework for the project. The biggest hurdle was always the per-developer cost for the commercial license of the framework. I would hear things like

Just use MFC. It’s free and we don’t really see a need for the application to be cross-platform anyway.

or sometimes I would hear

Use the GPL version of Qt and just keep it under the radar until we are sure the application will be released to our customers.

It was always frustrating to try and make the case that Qt was a better solution than MFC for UI, was more comprehensive for general development than other frameworks, and that it was worth planning for the possiblity of releasing the applications for Linux or Mac as well as Windows. In the end each project did adopt the Qt Framework, but it really was a distraction to try and justify the use.

Thankfully with the purchase of Trolltech by Nokia we are seeing a change in the licensing terms for the Qt Framework. Starting with the 4.5 release it looks like the framework will be placed under the LGPL license making it much easier to adopt as part of commercial development efforts.

Here are a couple links that discuss the development further:

and you can read the news directly from Nokia on the Qt Licensing Terms page.

This new development on the licensing front and the recent inclusion of WebKit into the Qt Framework make me very optimistic about a long and prosperous future for developers who know the Qt Framework! Thank you Nokia!

Advertisements

Use QImage to create a composite image (i.e. One image with another overlaid on top of it.)

qt.pngToday I wanted to combine two images of similar size to create a new image. The new image was going to be used for a toolbar button. I have purchased a set of commercial images in the PNG format for use on application toolbars. The set came with a bunch of overlay images that could be used to modify each of the base images. The overlays included things like arrows, warning signs, arrows, people, etc. My first though for using these images was to fire up Adobe Illustrator and just create a new icon by merging the base and overlay together. Then I realized that Qt could do the job for me at runtime, and with a little work I could dynamically overlay different badges on a base icon.

The code below can be used to construct a composite image. You pass in references to a base image and an overlay image. These images are used to construct a third image, and that is returned to the caller.

QImage createImageWithOverlay(const QImage& baseImage, const QImage& overlayImage)
{
    QImage imageWithOverlay = QImage(baseImage.size(), QImage::Format_ARGB32_Premultiplied);
    QPainter painter(&imageWithOverlay);

    painter.setCompositionMode(QPainter::CompositionMode_Source);
    painter.fillRect(imageWithOverlay.rect(), Qt::transparent);

    painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
    painter.drawImage(0, 0, baseImage);

    painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
    painter.drawImage(0, 0, overlayImage);

    painter.end();

    return imageWithOverlay;
}

Here is an example of using this routine to create an image that might be used to represent something being transfered from a network attached machine.

    QImage baseImage(":/Resources/connect_pc_64.png");
    QImage overlayLogoff(":/Resources/overlay_arrow_east_64.png");
    QImage logoffImage = createImageWithOverlay(baseImage, overlayLogoff)

The two source images and resulting composite are shown below.

  1. :/Resources/connect_pc_64.png
  2. :/Resources/overlay_arrow_east_64.png
  3. Generated Composite Image

HOWTO – Use Visual Studio 2005 for Qt Open Source Development

THIS IS A WORK IN PROGRESS. EXPECT UPDATES AND DON’T BE SURPRISED BY INCOMPLETE INFORMATIONqtlogo_feature.png

Trolltech has released Qt 4 under a dual-license for all supported platforms. In earlier versions of Qt they only released the open source version for Mac and Linux, leaving Windows developers with no choice but to purchase a commercial license. That all changed with the release of Qt 4 when Trolltech started to provide an open source version for Windows development too! The only catch was that Trolltech only supports the MinGW GCC compiler for development using the open source version.

This article describes how to patch Qt 4 open source edition on Windows so you can develop using Visual Studio 2005. You can even develop using the free Express edition of Visual Studio 2005 so long as you also install the latest Platform SDK.

Please keep in mind that these patches and tips are not provided so you can get around the very generous Trolltech dual-license terms of use. If you are developing or intend to develop a commercial application using Qt 4 you must purchase a commercial license for Qt 4. Only use the information provided in this article if you wish to develop open source GPL software for the Windows platform and wish to use the Microsoft Visual C++ 2005 compiler instead of the MinGW GCC compiler.

Download Qt 4.1 Source Code, Patches, and Notes

Building Qt 4.1 using Visual C++ 2005

Open C:\qt-win-opensource-src-4.1.0 in Windows Explorer.
Double-click on the “Qt 4.1 Command Prompt” shortcut to open a Command Prompt window with the environment setup for Qt 4.1 development. IMPORTANT: You must already have Visual Studio 2005 installed. You may need to edit setenv.cmd if your copy of Visual Studio 2005 is not in the default location.

Run “installpatch41.bat”
This will patch the Qt 4.1 source code so it builds properly using the Visual C++ 2005 compiler.

Run “build.cmd”
This will build all of the Qt 4.1 libraries, utilities, and sample applications using the Visual C++ 2005 compiler.

To rebuild, if necessary, make sure to first clean up the previous build. Do this by running
nmake distclean

from the C:\qt-win-opensource-src-4.1.0 directory.

External Tools Configuration in Visual Studio 2005

Launch Visual Studio 2005 and select the “External Tools…” item from the Tools menu.
Use the “Add button to define each of the following external tools:

Title ……………….. QMake (Project File Generation Mode)
Command ……………… D:\qt-win-opensource-src-4.1.0\bin\qmake.exe
Arguments ……………. -project -spec win32-msvc2005
Initial directory …….. $(ProjectDir)
Use Output window …….. [X]
Treat output as Unicode .. [ ]
Prompt for arguments ….. [ ]
Close on exit ………… [X]

Title ……………….. QMake (Makefile Generation Mode)
Command ……………… D:\qt-win-opensource-src-4.1.0\bin\qmake.exe
Arguments ……………. -makefile -spec win32-msvc2005
Initial directory …….. $(ProjectDir)
Use Output window …….. [X]
Treat output as Unicode .. [ ]
Prompt for arguments ….. [ ]
Close on exit ………… [X]

Title ……………….. Qt Designer
Command ……………… D:\qt-win-opensource-src-4.1.0\bin\designer.exe
Arguments …………….
Initial directory …….. $(ProjectDir)
Use Output window …….. [ ]
Treat output as Unicode .. [ ]
Prompt for arguments ….. [ ]
Close on exit ………… [ ]

Title ……………….. Qt Assistant
Command ……………… D:\qt-win-opensource-src-4.1.0\bin\assistant.exe
Arguments …………….
Initial directory …….. $(ProjectDir)
Use Output window …….. [ ]
Treat output as Unicode .. [ ]
Prompt for arguments ….. [ ]
Close on exit ………… [ ]
Adding a Qt 4.1 Development Toolbar

Add a new toolbar for Qt 4.1 Development by selecting “Customize…” from the Tools menu. Once the “Customize” dialog appears select the “Toolbars” tab and press “New…” For the toolbar name enter “Qt 4.1 Development” and press “OK”.
Select the “Commands” tab on the “Customize” dialog. Select “Tools” from the “Categories:” list. Scroll down in the “Commands:” list until you see “External Command 7”. Drag commands 7, 8, 9, and 10 onto the new “Qt 4.1 Development” toolbar.
Creating a New Visual Studio 2005 Project

Open the “New Project” dialog by selecting File->New->Project… from the menu. Under “Project types” on the left side of the dialog expand “Visual C++” and then select “General.” The right side of the dialog will display a list of all the general project types. Select “Makefile Project” from the list of project types. Provide a name for the project and set the location on disk where you wish the project to be saved. Be sure not to check “Create directory for solution”, as this will create an extra level of directories that is just confusing. Click the “OK” button and you will be presented with the “Makefile Application Wizard.” Simply press the “Finish” button on the first page of the wizard.

Once the project has been created and opened, set the NMake Configuration Properties for the project as shown below. In the “Solution Explorer” right-click on the name of your project. Select “Properties…” from the context menu. On the property pages dialog select “Configuration Properties” and “NMake” on the left side tree control. On the right side, enter the following information, making sure to set the properties for both the debug and release configurations.

Release Configuration Settings

General
——-
Build Command Line …………………. nmake release-all
Rebuild All Commaond Line …………… nmake release-clean release-all
Clean Command Line …………………. nmake release-clean
Output ……………………………. foo.exe

IntelliSense
————
Common Language Runtime Support ……… No Common Language Runtime support
Preprocessor Definitions ……………. WIN32;NDEBUG;UNICODE;QT_LARGEFILE_SUPPORT;QT_DLL;
QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT
Include Search Path ………………… “c:/qt-win-opensource-src-4.1.0/include/QtCore”;
“c:/qt-win-opensource-src-4.1.0/include/QtGui”;
“c:/qt-win-opensource-src-4.1.0/include”;
“c:/qt-win-opensource-src-4.1.0/include/ActiveQt”;
“c:/qt-win-opensource-src-4.1.0/mkspecs/win32-msvc2005”
Forced Includes …………………….
Assembly Search Path ………………..
Forced Using Assemblies ……………..
Debug Configuration Settings

General
——-
Build Command Line …………………. nmake debug-all
Rebuild All Commaond Line …………… nmake debug-clean debug-all
Clean Command Line …………………. nmake debug-clean
Output ……………………………. food.exe

IntelliSense
————
Common Language Runtime Support ……… No Common Language Runtime support
Preprocessor Definitions ……………. WIN32;_DEBUG;UNICODE;QT_LARGEFILE_SUPPORT;QT_DLL;
QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT
Include Search Path ………………… “c:/qt-win-opensource-src-4.1.0/include/QtCore”;
“c:/qt-win-opensource-src-4.1.0/include/QtGui”;
“c:/qt-win-opensource-src-4.1.0/include”;
“c:/qt-win-opensource-src-4.1.0/include/ActiveQt”;
“c:/qt-win-opensource-src-4.1.0/mkspecs/win32-msvc2005”
Forced Includes …………………….
Assembly Search Path ………………..
Forced Using Assemblies ……………..
QMake Project Settings

Create a project file called “foo.pro” in the directory for your makefile project. Replace the name “foo.pro” with the name of your actual application. Place the file in the directory where your Visual Studio project was created. To start with, the contents might look something like this:

CONFIG += qt
TEMPLATE = app
SOURCES += foo.cpp
HEADERS += foo.h
FORMS += foo.ui
You should be off and running now. For more detailed information I would suggest reading the qmake reference manual. You might also want to take a look at the Qt 4.1 tutorials in Qt Assistant. Have fun!