Do you want to know how your customers use your applications and devices? Try Qt Insight Beta.
最新版Qt 6.3已正式发布。 了解更多。
最新バージョンQt 6.3がご利用いただけます。 詳細はこちら

Update on UIKit lighthouse platform

Hi, it's been a while since you heard from me regarding the experimental, proof of concept, unsupported UIKit lighthouse platform. So, I thought I'd give you some overview on what happened in the meanwhile, and give you some instructions how to actually try this stuff for yourself. This is a bit of a long post :).

(Note that there also is a community effort going on to port pre-4.8 Qt versions to iOS on, which is not to be confused with this one.)

Since Lighthouse grew up, also the UIKit platform plugin went into the stock Qt 4.8 mainline, so if you get the sources for Qt 4.8, you'll be able to also try out Qt on iOS. More on how to get up and running below. But there also have been a few fridays since then, and luckily I had some time to improve things on the initial version.

Open GL ES 1/2, Performance!

The platform plugin now uses OpenGL ES for drawing, instead of painting to an image with the raster paint engine and blipping that to screen. This works out quite nicely, and gives usable performance.

Challenges: Qt's Open GL ES 2 code path resets the used frame buffer in between to a default value, in the unmodified case to the system frame buffer (0) - which doesn't exist on iOS (all rendering done in FBO's). The workaround is to override this by setting QGLPaintDevice::m_thisFBO (a protected member) in a custom subclass class and using that instead.

Nicer Fonts

The initial implementation used pre-rendered fonts shipping with Qt. Now it uses the BasicUnixFontDatabase from Qt, that is also able to handle ttf fonts. It's still using fonts shipped together with the application, not the actual fonts on the device though.

Challenges: None for me, since this was kindly contributed by IanFromAfrica, thanks a lot!!!

Text Input Support

The platform plugin now reacts on Qt's RequestSoftwareInputPanel and CloseSoftwareInputPanel events, by showing/hiding the iOS software keyboard. You can even input text / send key events by typing on it! ;)

Challenges: Showing the panel and handling simple key events is easy. (Implement UIKeyInput protocol on the main UIView.) Unfortunately Qt/QML doesn't seem to send sensible close events... . For the QDeclarativeView case the plugin checks the QML Item with activeFocus, and if this item looses activeFocus it closes the panel again. The application must make sure no input relevant parts are covered by the input panel. Also, there is no integration with the iOS clipboard, or magnifying glass.

Interface Orientation

If you specify initial and supported interface orientations in your application's Info.plist (UIInterfaceOrientation and UISupportedInterfaceOrientations), like it is done for any iOS application, the platform plugin will handle these. Your application will receive resize events, like it is standard in Qt applications, and the contents will be drawn flipped as needed.

Challenges: It would be nice if Qt could be told to draw rotated directly, since, as it is, the only way to do it is to draw the framebuffer transformed to screen (instead of directly transforming in GL), which probably has some performance implications.

Sound via Phonon

You can play sound using the Phonon API now. Nothing else really to say ;).

Challenges: None to speak of. Phonon and AVAudioPlayer API fit quite nicely. (Except for these prefinishMark notifications, which are just not supported atm. Not that any of this work is "supported", mind you :).)

Try it Now!

If you have access to a Mac OS X machine (you might want 10.6 or later) you can check Qt running on iOS right away. You don't necessarily need an actual device or be part of the (paid) developer program. The development tools and the iOS simulator are available for free (though you need to register with Apple to get them). So here is what you need:

  • A Mac OS X computer
  • Xcode developer tools, free download (need to register with Apple though)
  • A recent Qt 4.8, preferably from gitorious (you can also download a tar-ball from if you really want)

The second part can turn out to be tricky, because Apple does a good job on hiding away their free offering. If you happen to run Mac OS X Lion (10.7) you can just open the Mac AppStore that is installed in /Applications and download and install latest Xcode 4. If you are not running Lion, and are not registered with the paid iOS developer program, you can install Xcode 3 - if you find it. Here is a list of clicks:, "iOS Dev Center", "Downloads/Xcode 4", "Looking for Xcode 3? Download Now", Scroll down to the end to "Register as an Apple developer/Learn more", "Get started", then register, fill out all forms, accept all agreements, and finally download Xcode 3+iOS SDK. Only 4 GB, time to get some coffee ;) .

(If I have forgotten anything, please tell me, I'll then update the list.)

After you got the three things above you can go ahead and compile Qt. The README in src/plugins/platforms/uikit includes the necessary configure lines for the simulator and the device. You need to create shadow builds of Qt with the names qt-lighthouse-ios-simulator and qt-lighthouse-ios-device respectively (at least the examples require them to be there). E.g. if your Qt sources are located at /Users/me/Qt/qt-src you do a simulator build with

mkdir /Users/me/Qt/qt-lighthouse-ios-simulator
cd /Users/me/Qt/qt-lighthouse-ios-simulator
../qt-src/configure -qpa -xplatform qpa/macx-iphonesimulator-g++ -arch i386 -developer-build -release -opengl es2 -no-accessibility -no-qt3support -no-multimedia -no-phonon-backend -no-svg -no-webkit -no-scripttools -no-openssl -no-sql-mysql -no-sql-odbc -no-cups -no-iconv -no-dbus -static -nomake tools -nomake demos -nomake docs -nomake examples -nomake translations
cd src/plugins/platforms/uikit

(Isn't that a beautiful configure line.)

If you get weird configure erros, check that you use the iOS SDK 4.3. If not, consider either upgrading your iOS SDK, or adapt the QMAKE_IOS_SDK variable in mkspecs/qpa/macx-iphonesimulator-g++/qmake.conf and mkspecs/qpa/macx-iphonedevice-g++/qmake.conf .

After that finished, you can open the example Xcode projects in qt-src/src/plugins/platforms/uikit/examples, make sure that the "<example> simulator" target and the "iPhone 4.3 Simulator" platform are selected in the top tool bar, and press the (Build &) Run button!

Blog Topics: