Sunday, January 24, 2010

Qt Mobility Messaging API on Windows

Qt Mobility Messaging API on Windows supports the MAPI messaging standard. However, this isn't straightforward to set up, as the Qt Mobility documentation states:
On Microsoft Windows, MAPI header files are required to be installed, we recommend installing Visual Studio Express for this purpose.

So what should we do?

I've posted a question on Forum Nokia here.

Qt Mobility Messaging API on Linux

Getting Qt Mobility Messaging API to work on Linux (my Ubuntu Karmic Koala 9.10 system) needs some tricks.

The easiest way of test your setup is by compiling the Qt Mobility example writemessage.

Using my initial installation of Qt Mobility I got this error:
Starting: /usr/bin/make -w
.......
/usr/bin/ld: cannot find -lQtMessaging_tp
collect2: ld returned 1 exit status
make: *** [message-merge] Error 1
Exited with code 2.
Error while building project message-merge
When executing build step 'Make'

The most important error message is "cannot find -lQtMessaging_tp" which means that Qt Mobility Messaging library has not been properly built.



















Qt Mobility on Linux requires QMF.


The Qt Mobility Messaging API documentation points this out:


On Linux QMF is required to be installed and the QMF_INCLUDEDIR and QMF_LIBDIR environment variables set to the messagingframework/src/libraries/qtopiamail and build/messagingframework/image/lib directories respectively.

To install QMF, checkout the latest QMF from Gitorious:
git clone git://gitorious.org/qt-labs/messagingframework.git qt-messagingframework
If you don't have git or don't want to use it, you can also download QMF as tarball archive.
Then build it:
export PATH=/opt/qtsdk-2010.01/qt/bin:$PATH
qmake "QMF_INSTALL_ROOT=$PWD/image" qmf.pro
make
make install
Now you need to rebuild Qt Mobility with Messaging (QMF) support (change paths as necessary):

export PATH=/opt/qtsdk-2010.01/qt/bin:$PATH
export QMF_INCLUDEDIR=/opt/qt-messagingframework/src/libraries/qtopiamail
export QMF_LIBDIR=/opt/qt-messagingframework/image/lib
./configure
make
make install
Make sure it says "Checking QMF ... OK" during configure.
Add the following to your $HOME/.profile script:
necessary):
# Qt Mobility
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/qt-mobility-src-1.0.0-tp2/install/lib:/opt/qt-messagingframework/image/lib
export QMF_INCLUDEDIR=/opt/qt-messagingframework/src/libraries/qtopiamail
export QMF_LIBDIR=/opt/qt-messagingframework/image/lib
Once Qt Mobility Messaging + QMF is set, to use it add the following to your .pro project file:
CONFIG += mobility
MOBILITY = messaging
The writemessage example additionally uses the following workaround to link QMF library:
symbian|win32 {
} else {
# Temporarily link against local qtopiamail lib (should be part of the platform)
LIBS += -L $$(QMF_LIBDIR) -lqtopiamail
}
Then you should be set.

Troubleshooting

If you get this error while building a Qt Mobility Messaging app:
/usr/bin/ld: warning: libqtopiamail.so.1, needed by /opt/qt-mobility-src-1.0.0-tp2/install/lib/libQtMessaging_tp.so, not found (try using -rpath or -rpath-link)
/opt/qt-mobility-src-1.0.0-tp2/install/lib/libQtMessaging_tp.so: undefined reference to `QMailAccountKey::operator|=(QMailAccountKey const&)'
It means you have built Qt Mobility Messaging module properly, but you haven't specified the library path to QMF. See above workaround to link QMF library.
If you get this error when running a Qt Mobility Messaging app:
error while loading shared libraries: libqtopiamail.so.1: cannot open shared object file: No such file or directory
exited with code 127
It means you haven't set QMF_LIBDIR properly. If you have, you may need to restart your computer.

Saturday, January 23, 2010

Installing Qt SDK 4.6.1 with Qt Creator 1.3.1 on Ubuntu

Now that Qt 4.6.1 SDK and Qt Creator 1.3.1 has been released by Nokia, I need to update my previous tutorial on setting up Qt Mobility development.
  1. Download Qt SDK Development Environment.
  2. Install Qt SDK. Launch Terminal, go to the folder where you downloaded Qt SDK distribution, and run:

    chmod +x qt-sdk-linux-x86-opensource-2010.01.bin
    ./qt-sdk-linux-x86-opensource-2010.01.bin
At the end of installation, you will be presented with this message:
Apart from a C++ compiler, a number of development libraries need to be present to enable Qt Creator to build your Qt applications. On Debian and Ubuntu, use the following command in a terminal to make sure they are installed:
sudo apt-get install libglib2.0-dev libSM-dev libxrender-dev libfontconfig1-dev libxext-dev
If you're using QtOpenGL, you'll also need OpenGL development files. You can use the following command to find out which packages to install:
sudo apt-get install libgl-dev libglu-dev
So just do what it tells you to:
sudo apt-get install libglib2.0-dev libSM-dev libxrender-dev libfontconfig1-dev libxext-dev
sudo apt-get install libgl-dev libglu-dev
Make sure you add Qt bin folder to your PATH environment. Edit $HOME/.profile and add:
export PATH=/opt/qtsdk-2010.01/qt/bin/:$PATH 
Now you can build and run Qt applications.
To build Qt Mobility apps, continue to Installing Qt Mobility libraries.

Friday, January 22, 2010

Qt Creator 1.3.1 and Qt 4.6.1 Released

Straight from Nokia's Press Release:


Oslo, 19 January 2010 – Nokia today released version 4.6.1 of Qt: the cross-platform application and UI framework, and version 1.3.1 of Qt Creator: the cross-platform IDE for Qt development .  Qt 4.6.1 brings improvements to developers targeting Symbian, most notably introducing a binary compatibility guarantee as announced with the Qt 4.6.0 release in December 2009.  Both releases introduce bug fixes and optimizations made since the Qt 4.6.0 and Qt Creator 1.3.0 releases.

Also released today are updates to the Qt Visual Studio Add-in and Qt Eclipse Integration, as well as an updated build of the Qt SDK.  All Qt releases are available for download from http://qt.nokia.com/downloads.

Binary Compatibility Guarantee on Symbian
Qt 4.6.1 brings a binary compatibility guarantee for applications built for the Symbian platform, as announced with the release of Qt 4.6.0.  For more information, visit http://qt.nokia.com/products/platform/symbian.

Qt Beta for Maemo 5 Also Released
A Beta of the Qt port to Maemo 5 is now available for download, testing and feedback.  For more information, visit http://qt.nokia.com/developer/qt-for-maemo-developers.

For a detailed list of changes introduced with Qt 4.6.1, consult the changes file found in the packages, or browse the information contained in the Qt Developer Zone at: http://qt.nokia.com/developer/changes/changes-4.6.1. A detailed list of changes in Qt Creator 1.3.1 is available at: http://qt.nokia.com/developer/changes/changes-qtcreator-1.3.1.

Qt Creator 1.3 Help/Documentation Not Working?

I installed Qt Creator IDE 1.3 / Qt 4.6 SDK and having a problem that the Qt Creator Help/Documentation is not working / not showing / blank.

I've found the culprit, and the reason is because:
You have used QtCreator with some Qt version before, and now have installed the same Qt version in a different location: There's a bug   that in this case the information where to get the help file is not updated.

The solution is simple:
Please try explicitly removing the entries in Tools -> Options -> Help, and either restart QtCreator, or add the qch-files from your Qt version explicitly.

Doing the above procedure returns my Qt Creator help content properly.

Wednesday, January 6, 2010

Useful Qt Mobility & Symbian S60 Development Links

Moved to Qt Mobility Links & Resources page.

Installing Qt Mobility Libraries on Windows 7

UPDATE: This article is obsolete. Please refer to the latest article, Installing Qt Mobility Final Libraries on Windows 7.

By following this article, you should be ready to develop Qt Mobility applications on Windows.

Note: This is only for Qt for Windows installation. If you want to develop Qt applications for Symbian on Windows, click here.
  1. Install Qt SDK 4.6 + Qt Creator 1.3 for Windows.
  2. Install Strawberry Perl for Windows (~ 32 MB). The reason why Perl is needed is covered in the later in this article.
  3. Download Qt Mobility library sources.
  4. Unpack Qt Mobility source distribution into a folder without spaces, e.g. C:\qtmobility
  5. Apply this patch to config.tests/make/make.pro. You can use patch tool, but you can edit the file manually (view the patch to see changes).
  6. Launch Qt Command Prompt
  7. Set the PATH to Strawberry Perl :



    set PATH=%PATH%;C:\strawberry\perl\bin
    

  8. Go to your Qt Mobility folder and run configure:



    cd \qtmobility
    configure
    
    This will configure Qt Mobility build with default target directory: C:\QtMobility

  9. Build Qt Mobility:



    mingw32-make
    mingw32-make install

  10. Add C:\qtmobility\lib folder to your PATH environment variable (more on this below).
  11. To add Qt Mobility documentation in Qt Creator: Go to Tools -> Options -> Help -> Add. Then browse C:\qtmobility/doc/qch/qtmobility.qch
Now you're ready to develop with Qt Mobility on Windows. Check out Qt Mobility Quickstart App for an example.



Setting Environment Variables

In order to use Qt Mobility some environment variables need to be extended to locate the libraries, which are placed in the lib directory of the install path.

On Windows: PATH should be extended to include: C:\%TARGET_DIR%\lib

On my setup this folder is: C:\qt-mobility-src-1.0.0-tp2\lib



PATH can be extended through Start -> Settings -> Control Panel -> System -> Advanced -> Environment variables. Under System variables, select "PATH", click "Edit..." and append your Qt Mobility lib folder.

Reboot your system to apply your changes to system environment variables.

You're now ready to develop Qt Mobility applications in Windows. :-)

Problems I Encountered... So You Don' Have To


I first tried to unpack Qt Mobility into My Documents, but I can't compile it:
C:\Users\ceefour\Documents\qt-mobility-src-1.0.0-tp2>configure
C:\Users\ceefour\Documents\qt-mobility-src-1.0.0-tp2
Checking available Qt
4.6.0
Checking make
 "Cannot find 'nmake', 'mingw32-make' or 'make' in your PATH"
 "Aborting."
I tried to move it to a top-level folder (C:\qtmobility) but still getting the same error.

After reading Forum Nokia thread: Qt Mobility problem, I tried to reboot my computer, but didn't help. There's also steps to install Qt Mobility for Symbian.

After further investigation leads me that configure determines its expected build system to be symbian-sbsv2 based on running qmake on config.tests\make\make.pro :
C:\qt-mobility-src-1.0.0-tp2>qmake config.tests\make\make.pro
Project MESSAGE: symbian-sbsv2
Project MESSAGE: symbian-sbsv2
Project MESSAGE: symbian-sbsv2

C:\qt-mobility-src-1.0.0-tp2>make
'make' is not recognized as an internal or external command,
operable program or batch file.
So it's looking for make.exe, which doesn't exist on my system.

I harcoded BUILDSYSTEM=win32-mingw by patching configure.bat here:
...
    for /f "tokens=3" %%i in ('%QT_PATH%qmake %SOURCE_PATH%\config.tests\make\make.pro 2^>^&1 1^>NUL') do set BUILDSYSTEM=%%i

    set BUILDSYSTEM=win32-mingw

    if %BUILDSYSTEM% == symbian-abld (
...
Update: Use this patch.

and now configure seem to work...
C:\qt-mobility-src-1.0.0-tp2>configure
C:\qt-mobility-src-1.0.0-tp2
Checking available Qt
4.6.0
Checking make
hello
... mingw32-make found.

Start of compile tests
Checking LBT
'Y_MAKEPROJECT_LOG' is not recognized as an internal or external command,
operable program or batch file.
... Not Found
'compile' is not recognized as an internal or external command,
operable program or batch file.


"Generating Mobility Headers..."
The system cannot find the file specified.
'perl' is not recognized as an internal or external command,
operable program or batch file.
'perl' is not recognized as an internal or external command,
operable program or batch file.
'perl' is not recognized as an internal or external command,
operable program or batch file.
'perl' is not recognized as an internal or external command,
operable program or batch file.
'perl' is not recognized as an internal or external command,
operable program or batch file.
'perl' is not recognized as an internal or external command,
operable program or batch file.
'perl' is not recognized as an internal or external command,
operable program or batch file.
'perl' is not recognized as an internal or external command,
operable program or batch file.
'perl' is not recognized as an internal or external command,
operable program or batch file.

Running qmake...
Reading C:/qt-mobility-src-1.0.0-tp2/src/src.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/src/global/global.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/src/serviceframework/serviceframework.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/src/bearer/bearer.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/src/location/location.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/src/contacts/contacts.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/src/multimedia/multimedia.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/src/publishsubscribe/publishsubscribe.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/src/versit/versit.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/src/systeminfo/systeminfo.pro
Reading C:/qt-mobility-src-1.0.0-tp2/tools/tools.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/tools/servicefw/servicefw.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/tools/servicexmlgen/servicexmlgen.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/tools/vsexplorer/vsexplorer.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/tools/qcrmlgen/qcrmlgen.pro
Reading C:/qt-mobility-src-1.0.0-tp2/plugins/plugins.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/plugins/contacts/contacts.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/plugins/multimedia/multimedia.pro
  Reading C:/qt-mobility-src-1.0.0-tp2/plugins/multimedia/m3u/m3u.pro
  Reading C:/qt-mobility-src-1.0.0-tp2/plugins/multimedia/phonon/phonon.pro
  Reading C:/qt-mobility-src-1.0.0-tp2/plugins/multimedia/audiocapture/audiocapt
ure.pro
Reading C:/qt-mobility-src-1.0.0-tp2/doc/doc.pro
 Reading C:/qt-mobility-src-1.0.0-tp2/doc/src/snippets/snippets.pro
  Reading C:/qt-mobility-src-1.0.0-tp2/doc/src/snippets/qtcontactsdocsample/qtco
ntactsdocsample.pro

configure has finished. You may run mingw32-make to build the project now.
Time to run mingw32-make and pray:
...
g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT
-DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS
_QMAIN -I"c:\Qt\2009.05\qt\include\QtCore" -I"c:\Qt\2009.05\qt\include\QtGui" -I
"c:\Qt\2009.05\qt\include" -I"c:\Qt\2009.05\qt\include\QtContacts_tp" -I"..\..\.
.\..\src\global" -I"..\..\..\..\src\contacts" -I"..\..\..\..\src\contacts\reques
ts" -I"..\..\..\..\src\contacts\filters" -I"..\..\..\..\src\contacts\details" -I
"c:\QtMobility\include" -I"c:\Qt\2009.05\qt\include\ActiveQt" -I"..\..\..\..\bui
ld\Release\qtcontactsdocsample\moc" -I"c:\Qt\2009.05\qt\mkspecs\win32-g++" -o ..
\..\..\..\build\Release\qtcontactsdocsample\moc_requestexample.o ..\..\..\..\bui
ld\Release\qtcontactsdocsample\moc\moc_requestexample.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
oc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows -o ..\..\..\..\bin\examples\qtcon
tactsdocsample.exe ../../../../build/Release/qtcontactsdocsample/qtcontactsdocsa
mple.o ../../../../build/Release/qtcontactsdocsample/moc_requestexample.o  -L"c:
\Qt\2009.05\qt\lib" -lmingw32 -lqtmain -LC:\qt-mobility-src-1.0.0-tp2/lib -LC:\Q
tMobility/lib -lQtContacts_tp -lQtGui4 -lQtCore4
mingw32-make[4]: Leaving directory `C:/qt-mobility-src-1.0.0-tp2/doc/src/snippet
s/qtcontactsdocsample'
mingw32-make[3]: Leaving directory `C:/qt-mobility-src-1.0.0-tp2/doc/src/snippet
s/qtcontactsdocsample'
mingw32-make[2]: Leaving directory `C:/qt-mobility-src-1.0.0-tp2/doc/src/snippet
s'
mingw32-make[1]: Leaving directory `C:/qt-mobility-src-1.0.0-tp2/doc'

C:\qt-mobility-src-1.0.0-tp2>_
The build took a few minutes and it seems everything's fine.

P.S.: I could have just "given up" and install Symbian S60 SDK first. :-)

Compiling Qt Mobility with Debug enabled

If you try to develop a Qt Mobility app and using the Debug configuration (which is default), you'll get errors similar to these:

Running build steps for project locale-qt...
Starting: c:/qt/2009.05/qt/bin/qmake.exe C:/Users/ceefour/Documents/locale-qt/locale-qt.pro -spec win32-g++ -r
Exited with code 0.
Starting: C:/Qt/2009.05/mingw/bin/mingw32-make.exe -w
mingw32-make: Entering directory `C:/Users/ceefour/Documents/locale-qt'
C:/Qt/2009.05/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Users/ceefour/Documents/locale-qt'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\locale-qt.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -L"c:\Qt\2009.05\qt\lib" -lmingw32 -lqtmaind -LC:\qtmobility/lib -lQtSystemInfo_tpd -lQtGuid4 -lQtNetworkd4 -lQtCored4
mingw32-make[1]: Leaving directory `C:/Users/ceefour/Documents/locale-qt'
mingw32-make: Leaving directory `C:/Users/ceefour/Documents/locale-qt'
c:/qt/2009.05/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lQtSystemInfo_tpd
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\locale-qt.exe] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project locale-qt
When executing build step 'Make'

You have two choices:
  1. Build your project using Release configuration.
  2. Build Qt Mobility with Debug enabled as well.
To build Qt Mobility with Debug enabled, simply add the argument -debug to configure in the steps above:

configure -debug

Then repeat the build process as usual.

Installing Perl


I noticed some errors early in the "configure" process:
"Generating Mobility Headers..."
Access is denied.
'perl' is not recognized as an internal or external command,
operable program or batch file.
...
This is one reason why I hate hesitate to use Windows. Qt Mobility's include folder, which should contain the header files, is still empty. Time to install a Perl interpreter.

Get Strawberry Perl for Windows (~ 32 MB).

Strawberry Perl automatically adds itself to your PATH system variable, you can check this by running perl -v :
C:\strawberry>perl -v

This is perl, v5.10.1 (*) built for MSWin32-x86-multi-thread

Copyright 1987-2009, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
Unfortunately, Qt Command Prompt sets its own PATH environment variable, overriding. Before running configure, do:
set PATH=%PATH%;C:\strawberry\perl\bin
Now you can configure and build Qt Mobility on Windows properly.

See also: