×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Regular Contributor
    Join Date
    Oct 2007
    Location
    India
    Posts
    349

    Question How to prevent Screen Orientation in Qt for Symbian App

    I am developing an Qt Application for Symbian. I have to prevent Application Orientation. I mean I want to fix my app in Portrait Mode.

  2. #2
    Registered User
    Join Date
    Oct 2010
    Posts
    31

    Re: How to prevent Screen Orientation in Qt for Symbian App

    Download latest Qt SDK 1.1 RC.

    When you create a mobile project you'll be asked whether you want your app to be auto-rotating or being fixed in a portrait/landscape mode. Then you may check the code and see how it's done.

  3. #3
    Regular Contributor
    Join Date
    Oct 2007
    Location
    India
    Posts
    349

    Re: How to prevent Screen Orientation in Qt for Symbian App

    Quote Originally Posted by Pavel.Rusin View Post
    Download latest Qt SDK 1.1 RC.

    When you create a mobile project you'll be asked whether you want your app to be auto-rotating or being fixed in a portrait/landscape mode. Then you may check the code and see how it's done.
    Thanks for the instant reply. Actually I am using Nokia Qt SDK 1.0.2. And right now I dont want to update this SDK. So in SDK 1.0.2 how to prevent orientation.

  4. #4
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,357

    Re: How to prevent Screen Orientation in Qt for Symbian App

    try this
    Code:
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        MainWindow mainWindow;
        mainWindow.setOrientation(MainWindow::ScreenOrientationLockPortrait);
        mainWindow.showExpanded();
    
        return app.exec();
    }
    Code:
    void MainWindow::setOrientation(ScreenOrientation orientation)
    {
    #if defined(Q_OS_SYMBIAN)
        // If the version of Qt on the device is < 4.7.2, that attribute won't work
        if (orientation != ScreenOrientationAuto) {
            const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
            if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
                qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
                return;
            }
        }
    #endif // Q_OS_SYMBIAN
    
        Qt::WidgetAttribute attribute;
        switch (orientation) {
    #if QT_VERSION < 0x040702
        // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
        case ScreenOrientationLockPortrait:
            attribute = static_cast<Qt::WidgetAttribute>(128);
            break;
        case ScreenOrientationLockLandscape:
            attribute = static_cast<Qt::WidgetAttribute>(129);
            break;
        default:
        case ScreenOrientationAuto:
            attribute = static_cast<Qt::WidgetAttribute>(130);
            break;
    #else // QT_VERSION < 0x040702
        case ScreenOrientationLockPortrait:
            attribute = Qt::WA_LockPortraitOrientation;
            break;
        case ScreenOrientationLockLandscape:
            attribute = Qt::WA_LockLandscapeOrientation;
            break;
        default:
        case ScreenOrientationAuto:
            attribute = Qt::WA_AutoOrientation;
            break;
    #endif // QT_VERSION < 0x040702
        };
        setAttribute(attribute, true);
    }
    
    void MainWindow::showExpanded()
    {
    #ifdef Q_OS_SYMBIAN
        showFullScreen();
    #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
        showMaximized();
    #else
        show();
    #endif
    }

    Make sure that you need to extend the window, or else you can hide that

  5. #5
    Registered User
    Join Date
    Jun 2007
    Location
    Mumbai, India
    Posts
    1,998

    Re: How to prevent Screen Orientation in Qt for Symbian App

    You just have to add this in your main()


    // Symbian specific code
    #ifdef Q_OS_SYMBIAN
    CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
    TRAPD(error,
    if (appUi) {
    // Lock application orientation
    appUi->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait);
    }
    );
    #endif
    Last edited by kamalakshan; 2011-04-25 at 14:32. Reason: code formatting

  6. #6
    Regular Contributor
    Join Date
    Oct 2007
    Location
    India
    Posts
    349

    Re: How to prevent Screen Orientation in Qt for Symbian App

    Quote Originally Posted by kamalakshan View Post
    You just have to add this in your main()
    Headers for that ? Any entry in .pro ?

  7. #7
    Registered User
    Join Date
    Jun 2007
    Location
    Mumbai, India
    Posts
    1,998

    Re: How to prevent Screen Orientation in Qt for Symbian App

    Quote Originally Posted by narendar_discover View Post
    Headers for that ? Any entry in .pro ?
    Yes you will have to include these
    // Needed Symbian specific headers
    #ifdef Q_OS_SYMBIAN
    #include <eikenv.h>
    #include <eikappui.h>
    #include <aknenv.h>
    #include <aknappui.h>
    #endif
    and in your .pro file
    LIBS += -lcone -leikcore -lavkon

  8. #8
    Regular Contributor
    Join Date
    Oct 2007
    Location
    India
    Posts
    349

    Re: How to prevent Screen Orientation in Qt for Symbian App

    I am getting this error

    c:/nokiaqtsdk/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lcone

    collect2: ld returned 1 exit status

    mingw32-make[1]: *** [debug\GeoQponsQt.exe] Error 1

    mingw32-make: *** [debug] Error 2

  9. #9
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: How to prevent Screen Orientation in Qt for Symbian App

    Quote Originally Posted by narendar_discover View Post
    I am getting this error

    c:/nokiaqtsdk/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lcone

    collect2: ld returned 1 exit status

    mingw32-make[1]: *** [debug\GeoQponsQt.exe] Error 1

    mingw32-make: *** [debug] Error 2
    again you forgot to put the LIBS += -lcone -leikcore -lavkon in symbian block

  10. #10
    Regular Contributor
    Join Date
    Oct 2007
    Location
    India
    Posts
    349

    Re: How to prevent Screen Orientation in Qt for Symbian App

    Quote Originally Posted by skumar_rao View Post
    again you forgot to put the LIBS += -lcone -leikcore -lavkon in symbian block
    I have added this in .pro

  11. #11
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: How to prevent Screen Orientation in Qt for Symbian App

    but did you add it like

    symbian {
    LIBS += -lcone -leikcore -lavkon
    }
    Last edited by skumar_rao; 2011-04-25 at 18:44.

  12. #12
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to prevent Screen Orientation in Qt for Symbian App

    No need for the symbian qualifier if Symbian is the only target. It's just to prevent errors when targeting other platforms.

  13. #13
    Regular Contributor
    Join Date
    Oct 2007
    Location
    India
    Posts
    349

    Re: How to prevent Screen Orientation in Qt for Symbian App

    !! Perfect... ITS WORKING !!
    !! Thanks Everyone !!

Similar Threads

  1. How to create Multiple screen app in Qt for Symbian/Maemo?
    By narendar_discover in forum [Archived] Beginning Qt
    Replies: 7
    Last Post: 2011-04-25, 15:41
  2. How to prevent screen orientation change (5th ed.)
    By tunylund in forum Symbian User Interface
    Replies: 4
    Last Post: 2009-06-15, 08:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×