How to detect Rotate on Android?



  • Hi,
    I want to detect rotate on Android.

    on MainWindow::MainWindow(QWidget *parent),
    I use QScreen event: orientationChanged

    QScreen *s = QGuiApplication::primaryScreen();
        connect(s, SIGNAL(orientationChanged(Qt::ScreenOrientation)),
                   this, SIGNAL(orientationChanged(Qt::ScreenOrientation)));
    
         s->setOrientationUpdateMask(
                    Qt::PortraitOrientation
                    | Qt::LandscapeOrientation
                    | Qt::InvertedPortraitOrientation
                    | Qt::InvertedLandscapeOrientation);
    
    void MainWindow::orientationChanged(Qt::ScreenOrientation orientation)
    {
        qDebug() << "Orientation:" << orientation;
    }
    

    in header:

    public slots:
    void orientationChanged(Qt::ScreenOrientation orientation);
    

    but the event orientationChanged not fire.
    How do I get event when Android rotate?


  • Moderators

    Take a closer look at your code:

    connect(s, SIGNAL(orientationChanged(Qt::ScreenOrientation)),
                   this, SIGNAL(orientationChanged(Qt::ScreenOrientation)));
    

    You use SIGNAL where you actually should use SLOT.
    Change it to:

    connect(s, SIGNAL(orientationChanged(Qt::ScreenOrientation)),
                   this, SLOT(orientationChanged(Qt::ScreenOrientation)));
    


  • Thanks Jsulm,
    That's my typo


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.