Qt Development on OS X Mountain Lion

1. October 2012 21:18 by Cameron in C++, Mac, Mac OS X, Qt  //  Tags: , , , , , ,   //   Comments

OS X Mountain Lion changes a few things on how XCode is installed. Xcode is now contained in an app bundle and the SDKs directory is part of the bundle contents, thus you will need to update your SDK paths in your project file like so:

MAC_SDK  = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
    if( !exists( $$MAC_SDK) ) {
        error("The selected Mac OSX SDK does not exist at $$MAC_SDK!")

If you want to support Snow Leopard as a target platform with your Qt applications, be sure to use the 10.7 SDK and not the default 10.8 SDK. Your app should work just fine in Snow Leopard provided that you don't make any calls to Lion specific features while using the 10.7 SDK.

Another important thing is to install the command line tools for GCC so that Qt can find the compiler during installation and successfully compile C/C++ applications from Qt Creator. If you do use the 10.8 SDK with any Qt version less than Qt 5.0, it will give warnings that OS X 10.8 is unsupported during compilation. These warnings can be safely ignored. Aside from that, everything else should be the same as before. Happy coding!

Improving speed of iterating a result set from a QSqlQuery

4. July 2012 16:22 by Cameron in C++, Qt  //  Tags: , , , , , , , ,   //   Comments

Today, I had to figure out why it was taking so long to iterate a result set using a QSqlQuery. A query that I ran in about 1 second from SQL Server Management Studio was taking 15 seconds to complete from my C++ application. I found that if you don't set ForwardOnly to true using setForwardOnly(true), it will drastically decrease performance of iterating through the query's results. You should also prepare the query before executing. After applying those changes, I got my query to run in under a second! Huge difference! You can see an example of how to connect to a SQL Server database and query a table using the QODBC3 driver. The speed improvements should also apply to SQLite databases.

QString connectionTemplate = "DRIVER={SQL SERVER};SERVER=server;DATABASE=Users;";
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3", "db");
if (db.open()) {
	qDebug() << "OK!";
	QSqlQuery * query = new QSqlQuery(db);
	query->prepare("SELECT [UserName]"
				   "  FROM [dbo].[Users]");
	QTime begin = QTime::currentTime();
	if(query->exec())      {
			QString userName = query->value(0).toString();
			qDebug() << userName;
		QTime end = QTime::currentTime();
		qDebug() << "finished in " + QVariant(end.second() - now.second()).toString() + " seconds";
else {
	qDebug() << db.lastError().text();

Started Development of a Collapsible Frame Qt Widget

5. May 2012 22:14 by Cameron in C++, Qt  //  Tags: , ,   //   Comments

Today, I started development of a collapsible frame Qt widget. I needed a widget that could show/hide its contents by clicking on an open/close button but couldn't find a solution online so I decided to create my own. The code is still a work in progress, but the basis of the code involves the use of nested layouts to achieve the hide/show effect. I had to write a custom clickable label class and subclass QLabel as QLabel doesn't have a clicked() signal. I'm using style sheets to apply the icon to the QLabel so that it has the correct image based on open/close and hover over states. The code is available on github under the Apache 2.0 license. Feel free to check out the code and see if you'd like to fork it yourself and contribute.


Qt Cross Platform Notification System

25. March 2012 16:30 by Cameron in C++, Qt  //  Tags: , , , , ,   //   Comments

I've been working on a cross-platform notification system built on Qt which is modeled after Mac OS X's Growl notification system. This is for use in a project that I'm currently working on. You may view the source code here: https://github.com/pcmantinker/Tray-Notification-System

I am still playing around with the window flags for the notification system as sometimes when a new notification is shown, within the Windows operating system, it steals focus from full screen applications. If you have any suggestions, feel free to let me know in the comments. Also, feel free to fork my repository and contribute to the code base if you're interested.

Qt Application Development in Mac OS X Lion

1. February 2012 01:52 by Cameron in Qt, Mac OS X, C++  //  Tags: , , , , ,   //   Comments

I've been working on some code using the QtSDK lately and I've been researching how to deploy applications for Mac OS X 10.6 and above. Luckily, it's pretty simple to deploy applications as the QtSDK includes a tool called macdeployqt. The tool copies all required Qt frameworks to the app bundle and re-assigns the library reference paths for the app to use the libraries within the app bundle and not the user's system directory (/usr/lib). It doesn't copy 3rd party libraries that aren't in the /usr/lib directory so you will have to manually add those.

Please note that macdeployqt on Qt 4.7.x doesn't seem to assign the correct library paths when linking against QtWebKit. This is a known bug that was fixed in Qt 4.8.0.

Also, if you want to insure that your app will not have problems on Snow Leopard, be sure to add this to your .pro file: 


This tells Qt to use the Snow Leopard SDK instead of the Lion SDK. If you build your application with the 10.6 SDK, it will work with Mac OS X 10.6 or higher.

One last thing is that there seems to be a problem with Xcode 4 and Qt Creator not being able to find g++-4.2 which is installed with older versions of Xcode. A work around for this until a new version of Qt Creator:

sudo ln -s /usr/bin/g++ /usr/bin/g++-4.2

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

I hope this helps anyone experiencing the same issues.


As of the February 1, 2012 QtSDK update, it appears as though the problems with g++ and using macdeployqt have been fixed. Please be sure to update to the latest SDK release. 

Beginning Desktop Client for IGA

2. January 2012 18:45 by Cameron in PSN, Xbox Live  //  Tags: , , , , , , , , , , ,   //   Comments

After some time to think about the most secure method for processing achievements and trophies for an individual user using the user's account credentials, I've decided that using a desktop client rather than server side technology for collecting achievements and trophies is the best approach. Not only is it more secure, but it also reduces the load on my server by turning each user's computer into a node on the IGA network for processing small parts of achievements and trophy data as a whole. The combined data from each user will be uploaded to the IGA dedicated server for importing into the central database. Then data can be viewed from the web interface or smart phone applications.

The web interface and smart phone applications will merely serve as a way to interact with the data from the database rather than pulling data down from the various sources and taking up bandwidth. This is good for smart phone users as data charges can apply for checking for updates frequently.

I'm using a Qt, a cross platform GUI library, for designing the user interface so that the client may run on Windows, Mac OS X, and Linux out of the box. I will post some screen shots as they become available.

Month List

Tag cloud