Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

On tablet wrong angles from QRotationsensor regarding orientation



  • Hi,
    I'm developing a VR application for android via Qml Window.

    The app runs completely in landscape mode (android:screenOrientation="landscape").

    On my smartphones the app runs correctly, but on my asus tablet the angles (horizon, elevation) of the QRotationssensor seems to deliver values from the portrait mode.

    I tried it with setting the userOrientation() but unfortunately no effect.

    SRot::SRot(Set *pSet, QObject *parent) : QObject(parent)
    {
        m_pQrs = new QRotationSensor(this);
        m_pQrs->addFilter(this);
        connect(m_pQrs, &QRotationSensor::sensorError, this, &SRot::setError);
    
        m_pQrs->setAxesOrientationMode(QSensor::UserOrientation);
        m_pQrs->setUserOrientation(0); // i tried with 0, 90, 180
    }
    

    Has anyone an idea what else I could try?



  • The reason is probable that the accelerator coordinate axes relates to the default orientation, and this is by smartphones portrait and by tablets landscape. Is there a uniform way to programm an app for smarthpones and tablets which uses the accelerator/rotation sensors?


  • Moderators

    hi @PowerNow

    QScreen has a function/property that may help you here:

    nativeOrientation : const Qt::ScreenOrientation



  • hit @J.Hilk,
    thxs this was exactly I was looking for!

    QScreen *screen = QGuiApplication::screens().at(0);
    if(screen->nativeOrientation() == Qt::LandscapeOrientation) {
    }
    

    But now it's not possible (for devices with default LandscapeOrientation) to get the correct x,y rotation angles if keeping the device in landscape format. Why does AxesOrientation not works on my smartphones and tablets? This would be exactly what I needed.

    m_pQrs = new QRotationSensor(this);
    m_pQrs->setAxesOrientationMode(QSensor::UserOrientation);
    m_pQrs->setUserOrientation(90);
    
    qDebug() << "currentOrientation " << m_pQrs->currentOrientation(); // 0
    qDebug() << "isFeatureSupported " << m_pQrs->isFeatureSupported(QSensor::AxesOrientation); // false
    

    Does there maybe exist some transformations, functions, links...?


Log in to reply