Posts Tagged ‘symbian’

Locking screen orientation to landscape in Qt for Symbian

Sunday, January 31st, 2010

In my current project I’m programming a game for Symbian which will run only in landscape mode. So somehow I needed to lock the application to use only the landscape mode as some mobiles change the orientation automatically. I found a code snippet for that from Nokia’s forum.

The cone.lib, eikcore.lib, and avkon.lib Symbian libraries must be added to your Qt project:

//example_application.pro
  1. symbian: {
  2.     LIBS += lcone leikcore lavkon
  3. }

You also need some extra header files added to your source file:

//example_application.cpp
  1. #ifdef Q_OS_SYMBIAN
  2. #include <eikenv.h>
  3. #include <eikappui.h>
  4. #include <aknenv.h>
  5. #include <aknappui.h>
  6. #endif

Create a window to your app and include the  following code before the window is shown. It will lock the orientation to landscape mode:

  1. CAknAppUi* appUi = dynamic_cast (CEikonEnv::Static()>AppUi());
  2. TRAPD(error,
  3. if (appUi) appUi>SetOrientationL(CAknAppUi::EAppUiOrientationLandscape);
  4. );

Now the orientation is locked and it will not change manually by user or automatically.