How to detect Rotate on Android?
Unsolved
Mobile and Embedded
-
Hi,
I want to detect rotate on Android.on MainWindow::MainWindow(QWidget *parent),
I use QScreen event: orientationChangedQScreen *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? -
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)));