How declaring and using QOrientableSensorBase class to block the orientation of my tablet



  • @
    my .pro
    QT += core gui
    QT += sensors
    TARGET = SecretImage
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    SOURCES +=
    main.cpp
    FenPrincipal.cpp
    LabelClic.cpp
    HEADERS +=
    FenPrincipal.h
    LabelClic.h
    OTHER_FILES +=
    ressources.rc
    RC_FILE = ressources.rc
    RESOURCES +=
    ressourcimages.qrc
    @

    @
    my main.cpp
    #include <QApplication>
    #include "FenPrincipal.h"
    #include <QtSensors>
    int main(int argc,char *argv[])
    {
    QApplication app(argc, argv);

     *the mistake is  here with the terms  'QOrientableSensorBase' has not been declared*
    QOrientableSensorBase::setAxesOrientationMode(QOrientableSensorBase::FixedOrientation); 
    
                                                   
    FenPrincipale fenetrePrincipale(app.desktop()->width(),app.desktop()->height(),0);
    fenetrePrincipale.move(0,0);
    fenetrePrincipale.setStyleSheet("background-color:rgb(220,220,220)");
    fenetrePrincipale.show();
    return app.exec&#40;&#41;;
    

    }
    @

    I don't understand why QOrientableSensorBase class is not included into QtSensors. QOrientableSensorBase doesn't appears in the drop down list when I write #include<QtSensors/ (the list appears just after having writed/)
    I just would like to know what writing in my .pro and in my main.cpp to use the QOrientableSensorBase classe with the function setAxesOrientationMode(QOrientableSensorBase::FixedOrientation). I just want block the orientation of my tablet.
    I work with Qt creator3.1 and Qt 5.2.1.
    Thank you

    [edit: added missing coding tags @ SGaist]


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    This class is not part of QSensors, that's why it can't be found. It's available in the Qt Mobility module which had some parts ported to Qt 5.



  • Hi

    In my .pro, I added
    CONFIG+=mobility
    MOBILITY+= sensors

    but I always can't include QOrientableSensorBase class in my main.cpp.

    I work with Qt creator 3.1 and Qt 5.2.1 perhaps it is necessary to download and config Qt Mobility 1.2 on Qt creator before. If yes, where I can find explanations to do that. If no, what I should put in my .pro and in my main.cpp as #include< QOrientableSensorBase> and QOrientableSensorBase::setAxesOrientationMode(QOrientableSensorBase::FixedOrientation); for satisfaction
    thanks


  • Lifetime Qt Champion

    QOrientableSensorBase is not available in Qt 5 but you should have the same result with QSensor and setAxesOrientationMode



  • Thanks you for your reponse.

    My main.cpp is
    @
    #include <QApplication>
    #include "FenPrincipal.h"
    #include<QOrientationSensor>
    #include <QSensor>

    int main(int argc,char *argv[])
    {
    QApplication app(argc, argv);

    QObject *mobile = new QObject();
    QOrientationSensor *orientationTab = new QOrientationSensor(mobile);
    orientationTab->setAxesOrientationMode(QSensor::FixedOrientation);
    
    FenPrincipale fenetrePrincipale(400,400,0);
    fenetrePrincipale.show();
    
    return app.exec&#40;&#41;;
    

    }
    @

    I have no problem with the compilation, but the screen of my tablet doesn't stay fixed. I think to understand why, but I don't know how correcting it. I must define that my object is effectively my tablet, but I am not be able to do that. Can you help me and correct my main.cpp. I promise you that it will be my last question.

    Best regards

    [edit: added missing coding tags @ SGaist]


  • Lifetime Qt Champion

    You are leaking memory with your mobile variable that is never deleted and
    you don't start the sensor


Log in to reply
 

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