Archive for January, 2010

Qt Book Download: C++ GUI Programming with Qt 4 Second Edition by Jasmin Blanchette and Mark Summerfield (Prentice Hall)

January 30, 2010

Let me tell you, this is my kind of book.  On page 3 it has this listing:

#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
QApplication app(argc, argv);
QLabel *label = new QLabel(“Hello Qt!”);
return app.exec();

This opens a popup window with a label in it.

Then on page 5, it says to show bigger text with “Hello” in italics and Qt in red, replace

QLabel *label = new QLabel(“Hello Qt!”);


QLabel *label = new QLabel(“<h2><i>Hello</i> <font color=red>Qt!</font></h2>”);

That’s right.  Labels can have HTML formatted text in them!

The next page shows 11 lines of code to create a button that exits the app when pushed.

When I first started reading this book while waiting for my dinner to arrive, I thought to myself, this Qt thing is right up my alley.  And this book is also right up my alley, the pragmatic, no nonsense introduction to a pragmatic, no-nonsense C++ application framework.  There’s a reason why it is required reading for new hires at Nokia….

Best of all, it’s FREE! Published under the Open Publication License, it is perfectly legal to distribute.  It’s currently hosted on the website here:  download, but no guarantees if I will have to take it down if my bandwidth gets used up!    You can always download the torrent. But it’s such a good read, I recommend you purchase a hard copy.

Edit April 25, 2009:  The book’s source code is available for download from InformIt.


How to: Setup Qt 4.5+ Visual Studio Integration

January 30, 2010

(NOTE:  This post was originally published on Mar 06, 2009.  It was subsequently moved to the blog service and updated reflect the many comments.  Thank you for contributing your comments!


Qt is a cross platform GUI toolkit which was acquired from Trolltech by Nokia.  Starting with Qt 4.5, it is dual-licensed under both LPGL and Commercial.  The Commercial license can be a bit pricey, but the LPGL license means you can use it free of charge to develop proprietary, commercial, closed-source software.  Instantly, Qt has become available to a wide audience of software developers (DCSoft included).  Thank you Nokia!

More than a year ago, DCSoft has become very interested in Qt.  Much as we love MFC, it hasn’t changed much since 1999, and this is 2009.  Qt is easy to learn given its concise syntax and documentation, plugs into Visual Studio (more below), comes with a supported toolset including Designer (a resource editor), Linguist (a localization tool), and Qt Creator (an IDE), giving Qt more momentum than MFC, and a higher performance alternative to .NET.  It’s easily one of the best ways to create Windows apps, never mind it can also target Mac, Linux, and several embedded devices.

Starting with Qt 4.6, the LPGL version now comes pre-built for Visual Studio 2008 RTM.  If this fits your need, you can simply install it and skip to INSTALL VISUAL STUDIO ADD-IN. However, you will need to build Qt yourself if:

  1. You are using VS 2008 and you have installed SP1 and/or the ATL Security Update, and you are building your app with the _BIND_TO_CURRENT_VCLIBS_VERSION defined (or another means to specify the non-RTM version).  This is because both Qt and your app need to be built with the same version of the Visual Studio redistributables, and Qt has been built with RTM, but your app is not being built with RTM.
  2. You are using any version of VS 2005.  This is because Qt does not come prebuilt for VS 2005.

Here’s how to get our favorite IDE (Visual Studio 2005/2008) working with Qt!


As the option to download only the Qt source code is a bit obfuscated on the current Nokia website, please follow these directions:

  1. Go to and click the Go LGPL button.
  2. Since you want only source code, look at the Qt: Framework Only column on the right.  Click e.g. Download Qt libraries 4.6.1 for Windows (VS 2008, 194 MB) — choose the VS2008 one.
  3. This starts the download for pre-built Qt.  But we don’t want that as we will be building Qt ourselves.  A page will appear with <Source code available on this link>.  Cancel the Save As dialog in your browser to cancel the binaries download you had clicked on, then click on this link, e.g.
  4. Unzip the file into e.g. c:\qt\4.6.1-vc.  Please use a path with no embedded spaces, as the Qt build tools have issues with them.


Open Computer Properties | Advanced system settings | Environment Variables:

  1. Edit environment variable to add:  QTDIR = c:\qt\4.6.1-vc
  2. Edit the PATH environment variable to add:  %QTDIR%\bin
  3. Either close all command prompts and Visual Studio instances, or reboot the computer so the new command-line takes effect.


  1. Open a Microsoft Visual Studio Command Prompt, which is a command console with environment variables set for the specified VS.  This is easily accomplished using Start | All Programs | Microsoft Visual Studio 2005 (or 2008) | Visual Studio Tools | Visual Studio 2005 (or 2008) Command Prompt.
  2. Cleanup any previous build:
    1. c:\> cd c:\qt\4.6.1-vc
    2. c:\qt\4.6.1-vc> nmake distclean
    3. c:\qt\4.6.1-vc> rm -rf tmp*  // <– recursively remove all tmp\ folders and files

This requires finding a *nix workalike.  I use Total Commander to search for Tmp*, select all the found files, and delete them with one keystroke.

3. Run Configure to target platform vc2005 or vc2008:

c:\qt\4.6.1-vc> configure -platform win32-msvc2005 <other options as needed>

Substitute win32-msvc2008 for VC2008

Run Configure with no parameters to see a help screen.  Configure generates nmake compatible makefiles to build all the Qt DLL’s, tools, and demos.

4.  Run nmake to build.

c:\qt\4.6.1-vc> nmake

It will take awhile, but this grinds through building the specified Qt DLL’s, tools, and demos with Visual Studio.


The Qt Visual Studio Add-in is indispensible for developing Qt apps in Visual Studio. The Add-in has replaced the previous Qt Visual Studio Integration, which was only available to Commercial customers.  Now the Add-in is used by both LPGL and Commercial licensees, and the Integration has been deprecated.  While the Add-in does not allow integrated .ui editing (it instead launches Qt Designer to edit .ui files), it is fully supported and maintained by Nokia, whereas the Integration hadn’t been modified since the 4.3/4.4 timeframe.

Because Visual Studio Express does not allow add-ins, using these free versions of Visual Studio is not recommended for Qt development.  You need at least Visual Studio Standard (Pro, Team System, etc. of course will also work).

1.  Download and install the Qt Visual Studio Add-in to install the Qt plug-in into Visual Studio (both 2005 and 2008 are supported by the add-in).

2.  Start Visual Studio.

3.  Select menu Qt | Configure Qt Versions.  Add c:\qt\4.6.1-vc.

4.  Now Qt is fully functional, and you can use VS2005/2008 to build Qt apps.


1.  See Qt menu item.  Launch Qt Designer (the Resource editor) and Qt Linguist (the localization tool).

2.  Create new Qt projects.  File | New project, select Qt4 project.

3.  Read Qt Help.  Available from Help menu (Qt help is merged in with Visual Studio Help and viewed in Document Explorer.)  Or, manually launch


4.  The Whole Tomato Visual Assist X plug-in is highly recommended to develop Qt within Visual Studio.  See this blog entry for tips.

Reducing our commute with GotoMyPC and Camtasia

January 22, 2010

One of the big benefits of being an offsite consultant is the improved quality of life.  Having commuted every workday for years, it is truly a blessing to gain an extra hour or two per day, as well as the energy normally spent gritting teeth as traffic inches forward.  Not to mention the gas savings (even my Honda Civic which gets 33 miles per gallon, at $4/gallon, this is still worthwhile).

Still, nothing beats a face to face meeting, and we’ve seen contractors fail to deliver and subsequently fall from grace with the client, due to misundrestandings that simply don’t occur when you’re regularly onsite.  How to get this benefit without actually being there?  We’ve become instant fans of GotoMyPC and Camtasia, both of which have saved us many commute hours.

GotoMyPC allows us to access a PC using a browser.  Although there are cheaper solutions such as LogMeIn (which is free), GotoMyPC’s performance (approaching that of Microsoft Remote Desktop) and ease of use make it well worth the cost.  As an additional benefit, you can share your desktop with another person over the Internet; he or she can use mouse and keyboard to control the desktop simultaneously with you.  It’s like the two of you are collaborating side by side, but it’s actually better because you have your own private screen/keyboard and don’t have to share!  It’s hard to beat GotoMyPC for two-way, interactive communication.

Camtasia records your screen along with your voice, making it easy to create Flash-based videos (which look good and aren’t huge).  Since everyone has the Flash plug-in, simply e-mail the url where you’ve uploaded the video and it instantly streams to their browser and starts playing within seconds.  Creating videos allows clients to see the product actually running as well as deep dives into the Visual Studio IDE to discuss technical coding issues.  Compared to being there, the information is conveyed with near 100% accuracy.  Both client and contractor prefer it to a physical meeting, since it’s less stressful and eliminates another time commitment.  I figure if I can save a handful of trips per year to client sites by recording Camtasia videos, it will easily pay for itself. – our journey from the comforts of Visual SourceSafe

January 22, 2010

As many Windows developers know, there is no source control system that is as easy as Microsoft Visual SourceSafe.  It comes with many versions of Visual Studio and is the justifiable default.  We’ve been using it for many years now, and laughed when we saw other developers keeping multiple directories with various versions of source code on their hard disks.  Seriously, if you are doing that, you really need to do yourself a favor and start using SourceSafe.  It gives you a safety net to easily go back to known good points in your development, as well as quickly determine what code you have changed.  It will also shield your from other people’s code changes, since it will do the painful merging for you at checkin time (you only have to resolve conflicts when the same lines of code are changed by someone else; most notably, in resource.h and the .rc file!)  Once you try it, you will feel so much more secure, that you will not go back.  SourceSafe looks like Windows Explorer, so you have very little to learn.  You will be up and running very quickly.

Alas, we stayed with SourceSafe as long as possible, but eventually outgrew it.  When remote subcontractors became involved in our projects, SourceSafe no longer suited, as it is far too slow for remote access over a VPN.  We also got tired of running Analyze all the time, and it was a constant reminder that we were using a not-totally-supported product.  We also yearned for integrated bug tracking (where you can associate a bug number with a checkin, and thus easily access the code from the bug report).  But what else is there beyond SourceSafe?

We were looking for a package that was as simple and inutitive as SourceSafe, yet more reliable and usable to access remotely.  Since SourceSafe is free if you have Visual Studio, cost is also an issue.  The short list included:

  • SourceGear – designed similarly to SourceSafe, but solving the reliability and remote access problem.  Con:  expensive, setting up server is complex.
  • Perforce – a rock solid package, but depot/clientspec concept is complex, P4Win is not pretty.  Con:  expensive, setting up server is too complex, Diff and merge tools are lacking, Integrated bug tracking with Bugzilla doesn’t work well.
  • Seapine – Many of the same benefits and disadvantages of Perforce, but on the whole more user friendly.
  • Subversion – at first, this OpenSource project left us cold, but after some friendly hands pointed us to the TortoiseSVN client, we were quickly won over by it’s simplicity and well-constructedness.  But installing the server still was very complex, and there was no integrated bug tracking.

Solution:  use Subversion, but through a hosting service  The server is already set up, and the service also adds integrated bug tracking.  We’ve been using for about a month now and are very happy with it.  We also tried and were reasonably happy with but prefer the more polished UI of Unfuddle.  As well, the proprietary Unfuddle Ticket system (bug tracking) is just superb, much better than Trac (which is another open source bug tracking project that supplements Subversion).

“Hosted” you say?  Surely you would never store the crown jewels of source code on someone else’s server.  No sir!  Well, admittedly, we held off on using a hosted solution for several months until the pain point of not having a collaborative version control system forced our hand.  We simply were not going to invest in setting up an Internet-facing server of our own; not only is this not our expertise, but it also requires getting a business-class (symmetric upload and download speeds) broadband connection for it.  So it was hosted or nothing.

And we do take precautions.  All Unfuddle access is via https.  As for storing the source code on a third party’s server, that is really no different than hosting your company’s e-mail on someone else’s server, and exchanging source code with other developers through e-mail attachments is quite common.  So when you look at it like this, you could argue that the risk of using a third party server is the same for both e-mail and source code, and that risk is deemed sufficiently low for both practices.

We highly recommend Unfuddle for mere mortals (like us), and if you are more of a propellor-head, then you may be more at home with CVSDude.

Welcome to the DCSoft Blog

January 22, 2010

Welcome to the DCSoft blog… here you will find useful tidbits from our experience running a small software consulting company.