Follow us: social_twitter_button_blue_16social_facebook_button_blue_16

Deskew Blog

Programming, music, software and hardware!
Tags >> Qt
 
Mac OSX App Store
If you use Qt to build your application for Mac OSX – you must have heard about the new OSX App Store that just opened in January, 2011.
 
The App store resembles the app store used for iOS devices hoping to bring the similar, streamlined experience, to the end-user. For us developers – this is great news … as long as we make our software so it doesn’t break the rules that Apple set forth.
 
In particular, there are certain steps one needs to perform to create a package compatible for submission to the app store and the application itself needs to follow certain guidelines.  Files cannot be written to certain folders, UI must have a consistent OSX look and so on …
 
We are not sure yet what that means for Qt based applications, but we are willing to give it a shot.
Our music notation product – Scorecerer has a desktop application that is built on top of Qt and it runs on OSX and Windows. We have built a free version of Scorecerer (Scorecerer Lite) and submitted it to the OSX app store. We are still waiting for the verdict and will soon know if Qt applications can or cannot be included in the OSX app store.
 
There seems to be a big debate going on in various forums, but most seem to simply speculate and paint Apple as “evil” without even trying to submit their app. Once we have the verdict – we will share it here with you so you will know for sure.
 
If Scorecerer Lite gets approved and published on the OSX app store – I will post the exact steps on how to prepare and submit your Qt app to the app store. Make sure you check our blog often for the latest news on this.
 
In the meantime we can only wait and hope that Qt libraries themselves do not break some of the Apple’s rules.
 
UPDATE: Today we got a rejection email from Apple. The list of reasons is long and we could address most of the issues, but there is one related to Qt itself
 
The application is creating files or writing to the following locations:

~/Library/Preferences/com.trolltech.plist
 
This is obviously done by Qt itself and as long as it is there - we will not be able to submit to the app store. We will try to see if there is a  solution to this problem, but in the mean time - your Qt application will be rejected because of this!
 
 

If you are using Qt as your development tool – most likely you are targeting different platforms. Deployment techniques for different platforms vary and there are a few “gotchas” that you should be aware of.
 
For OSX – you should use the macdeployqt command that comes with Qt on OSX. To use it – simply go into the folder where your application is and run the tool giving it your app name as the parameter. 
 
macdeployqt Foo.app
 
This packages everything nicely into one bundle that you can distribute to someone who does not have Qt installed on their system. I assume that this build is a “Release” build and I assume that you will be able to either create an installation package or an installable .dmg file
On Windows – things seem to be simple at a first glance as well, but there are a few things you should pay attention to.
 
Copy your .exe into a new folder and try to run it. You will immediately get a note about some missing dlls. You can keep trying this and copying the dlls needed into the folder, but a better way is to use Dependency Walker tool and drop your executable into it. It will show you most dlls you need to run the application.
 
The fun starts when these modules are loaded on demand in the application’s code. This is the case with the Qt “plugins”. They will not show on your dependency tree and your application may appear to be running, while in fact it will crash or worse – continue to work without desired functionality when these plugins are required and you are NOT on a machine that has Qt installed.
 
The real trouble is that Qt will look for those in a specific folder within your application AS WELL AS the main Qt plugins folder - this makes your installation impossible to test unless you are on a machine that does not have Qt installed.
 
An example of this are the Qt image processing plugins that allow you to load various file formats into a QImage object. 
 
Plugins are located under the “plugins” folder in your main Qt installation folder. Within that folder you will have subfolders for each group of plugins. For image processing – the name is “pluginsimageformats”. 
 
To make this available on the target machine – you have to place the folder called “imageformats” under the main folder where your executable file is. So if you are installing your application into “C:Program FilesMyGreatAppMyGreatApp.exe – you have to install a folder “C:Program FilesMyGreatAppimageformats” into it and copy all the dlls you need there.
 
So – it’s really easy to deploy a Qt App on Windows or Mac, but watch for a few of these little tricks. Always test your build on a machine that does not have Qt Installed before deployment. (something I didn't do last time and a reason for this blog entry :))

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