Follow us: social_twitter_button_blue_16social_facebook_button_blue_16

Deskew Blog

Programming, music, software and hardware!
Tags >> C++

I have been bitten for years whenever I have used precompiled headers with C++ platforms. It doesn't matter what platform I'm using, they just never quite seem to work properly and reliably. From time to time you just get bizarre error messages that just don't make any sense. So as a matter of course I just leave that option turned off and suffer the extra compilation time.

Recently, I've been working with Xcode 4 which we use for our Scorecerer iPad development. Precompiled headers are enabled by default and one of the first things I did was turn that option off and forgot about it.

However, one of my partners who also just switched to Xcode 4 did not turn off that option and guess what --- he just got bitten. In his case, he built an update of the product with changes that I checked into our version control system. The code compiled and built perfectly but the Xcode IDE still displayed a bunch of those red error marker icons in various places and suggested that some classes and some variables were missing. Cleaning the project and rebuilding made no difference.


Cross-platform development for desktop applications is becoming increasingly important. Chances are that your application user uses OS X, Windows, Linux or has a combination of these. For example - it is not uncommon for people to have a Windows based desktop and an OS X laptop.

In the recent years OS X platform really took off with the introduction of Intel based Macintosh computers. This makes the OS X platform hard to ignore.

As a developer - you have a few tough choices to make, but by far the toughest one is selecting the right development environment.


When NULL == false in QVariant

Posted by: djogon in Software Development

Tagged in: Qt , NULL , C++ , boolean

djogon
I’ve spent some time hunting down a problem where our QSettings (a Qt framework settings class) derived convenience class would not read Boolean values properly.
 
We wrapped the “Read” function with a code similar to this
  
template  T Read(ConstString name, T defaultValue)
{
   T result = defaultValue;  // Assume
     if (Exists(name))
        then QVariant v = this->value(name);
     if (v != NULL)
        then result = v.value();

   return result;
}
The idea is simple – if the value exists we read it, if not we use the supplied default value.
 
The line
   If (v != NULL)
fails miserably if v is a Boolean value.
 
If v is a boolean type and its value is false – then the v == NULL expression evaluates to true.
This is understandable since NULL expands to 0 and 0 is considered false. I wish NULL would be reserved for pointers in C++ so that the compiler could complain whenever one tried to use it for anything else but to signify a NULL POINTER!
 
So rather than testing the QVariant for NULL – use its member function isNull to test if it is really null.
 
The if statement above should be written as  
   If (!v.isNull())   ...
Everything works perfectly afterwards.
 
Btw. If you are wondering what is a Pascal style “then” doing in our C++ if statements – we believe that “then” is making our if statements much more readable. It is simply defined as nothing
 
#define then