Archived:Lock application orientation in Qt for Symbian
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
The example illustrated here uses the avkon libraries and was recommended until Qt 4.7.1. From Qt 4.7.1 you can instead use the instructions in Archived:Lock application orientation in Qt.
The example illustrated here uses the avkon libraries and was recommended until Qt 4.7.1. From Qt 4.7.1 you can instead use the instructions in Archived:Lock application orientation in Qt.
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): Qt
Article
Keywords: QApplication, CAknAppUi, EAppUiOrientationLandscape
Created: tepaa
(20 Oct 2009)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Overview
This example shows how to lock the application orientation.
Preconditions
- Qt is installed on your platform.
- Download Qt release from here: [1]
Qt project file
You must add the cone.lib, eikcore.lib, and avkon.lib Symbian libraries into the Qt build for orientation handling.
symbian: {
// Define UID3 for the Symbian app.
// Qt 4.6 beta release force to define that.
TARGET.UID3 = 0xSOMEUID
// cone.lib, eikcore.lib and avkon.lib Symbian libraries
LIBS += -lcone -leikcore -lavkon
}
Source
Here is an example of a Qt application main.cpp source file where the application orientation is locked into landscape.
#include <QtGui/QApplication>
#include "SomeMainWindow.h"
// Needed Symbian specific headers
#ifdef Q_OS_SYMBIAN
#include <eikenv.h>
#include <eikappui.h>
#include <aknenv.h>
#include <aknappui.h>
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
SomeMainWindow w;
// Symbian specific code
#ifdef Q_OS_SYMBIAN
CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
TRAPD(error,
if (appUi) {
// Lock application orientation into landscape
appUi->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape);
}
);
#endif
w.showFullScreen();
return a.exec();
}
Postconditions
The application orientation is landscape, and it does not change even if the device orientation is changed by the user.


The example is slightly flaky -- it should surround the SetOrientationL call with Q_TRAP_THROWING:
QT_TRAP_THROWING(appUi ->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape);)
dynamic_cast should not be used
Typecasting in Symbian
As Run Time Type Information (RTTI) is not supported, dynamic casting ( dynamic_cast<type>(exp) ) should not be used in symbian.
Kaalaththy - Orientation Lock in QT
Hi , I have tried and searched lots of coding to lock the orientation but finally it is one line of code QDeclarativeView view; view.setSource(QUrl("Your QML File name has to given"); view.setAttribute(Qt::WA_LockLandscapeOrientation);
The Orientation lock works fine in Mobile but not in simulator, So to check the orientation use Mobile.
Hope it will be useful for most of the developers to lock the orientation in QT.
Thanks.kaalaththy 16:21, 19 June 2012 (EEST)