Recently, I got interested in the new Windows Phone 8 platform. The new version brings the native-enabled or the native-only apps, which allows to write and run C/C based apps.

I were thinking about porting my ayuine2c to the WP8, but there was one problem. The project it’s written in Qt and by that time, no such port existed. I started by looking at: aknights-qtbase and Qt 5 on Windows 8 and Metro UI. Then after few sleepless nights I managed to compile all of the qtbase modules (core, network, gui, widgets…). I did some tests, and guess what, it works. There’s still a lot of functionality missing and not everything is tested as it should be, but in general works, quite well :)

The below is detailed compilation procedure.

1. Getting the source

Open Git Shell and clone sources

git clone git://gitorious.org/~ayufan/qt/qtbase-winrt.git qtbase -b qt5-winphone

2. Compiling Qt sources

Open Developer Command Prompt for VS2012:

    configure -prefix E:githubqt5qt5-winphone-arm-msvc2012 -debug-and-release 
        -xplatform winphone-arm-msvc2012 -no-openssl -no-vcproj 
        -nomake tests -nomake examples -nomake demos -no-sql-sqlite

Configure will fail due to new architecture detection mechanism:

    copy qmake.exe E:GitHubqt5qtbasebinqmake.exe
    1 file(s) copied.
    NMAKE : fatal error U1077: '"C:Program Files (x86)Microsoft 
            Visual Studio 11.0VCBINlink.EXE"' : return code '0x450'
    Stop.
    Could not find output file: No such file or directory

There is problem with compiling arch.exe for ARM using current VC compiler.

Open second window: Visual Studio 2012 ARM Phone Tools Command Prompt:

    cd config.testsarch
    nmake clean all
    cd ....

Go back to Developer Command Prompt for VS2012:

    configure -prefix E:githubqt5qt5-winphone-arm-msvc2012 -debug-and-release 
        -xplatform winphone-arm-msvc2012 -no-openssl -no-vcproj 
        -nomake tests -nomake examples -nomake demos -no-sql-sqlite

After while configure should finish. You should see something like this:

    QMAKESPEC...................winphone-arm-msvc2012 (detected)
    Architecture................arm, features:
    Host Architecture...........i386, features: sse sse2
    Maketool....................nmake
    Debug build.................yes (combined)
    Default build...............debug

    ...

    Generating Makefiles...


    Qt is now configured for building. Just run nmake.
    To reconfigure, run nmake confclean and configure.

Compile host tools:

    nmake sub-src-qmake_all
    cd srctools
    nmake
    cd ....

Go to Visual Studio 2012 ARM Phone Tools Command Prompt window and compile Qt5 for WP8:

    nmake
    nmake install

It will compile and install binaries, includes and libs into previously specified prefix directory.

3. Compiling Qt project

Open Visual Studio 2012 ARM Phone Tools Command Prompt. In project’s directory:

qmake -spec winphone-arm-msvc2012 -tp vc

It will create vcproj for Visual Studio 2012. Qmake creates WMAppManifest.xml. There is still ApplicationIcon.png missing. You have to put any png image and you are free to compile project within VS and run it on the phone.

4. Examples

Here you can find example projects based on Qt5.

4.1. TestApp

It’s simple widget app with QMainWindow. Sources and XAP

4.2. Wiggly

It’s simple demo from Qt examples. Sources and XAP

4.3. ayuine2c

My graphics engine working on WP8. Sources can be found at: git.ayufan.eu and XAP

5. Binaries

If don’t want to build it by yourself, you can use this precompiled binaries: Qt5 SDK for WP8

6. What about WinRT?

It’s definitely possible, but there is one caveats. The API’s available for WinRT (exactly: the Windows Store Apps) are more stripped down than for Windows Phone. One of missing subsystems is the Winsock2. In general the whole network stack needs to be rewritten from scratch. There should be guys that started doing it, but it will require some serious coding. However, if you are pretty anxious, you can try and compile it by yourself, but… In order to compile some of the Winsock2 headers needs to be patched.

Open Git Shell and clone sources

git clone git://gitorious.org/~ayufan/qt/qtbase-winrt.git qtbase -b qt5-winrt

Open Developer Command Prompt for VS2012:

    configure -prefix E:githubqt5qt5-winrt-x86-msvc2012 -debug-and-release 
        -xplatform winrt-x86-msvc2012 -no-openssl -no-vcproj 
        -nomake tests -nomake examples -nomake demos -no-sql-sqlite
    nmake
    nmake install