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

Ambient Temperature Sensor



  • Hello everyone!
    I am trying to work with the AmbientTemperatureSensor in Qt Qml for Android.
    I have just ran the Qt example called accelbuble(https://doc.qt.io/qt-5/qtsensors-accelbubble-example.html). And just added nexn code to the qml part:
    Rectangle {
    x:0
    y:0
    width:200
    height:200
    TextField {
    id: txt
    anchors.fill: parent
    text: (temp.reading ? temp.reading.temperature : "unknown")
    }
    }

    AmbientTemperatureSensor {
        dataRate: 100
        active: true
    
    
        id: temp
    
        onReadingChanged: {
            var t = (temp.reading ? temp.reading.temperature : "unknown");
            txt.text = t;
            console.log("Temp: ",t);
        }
        
    
    }
    

    But the program always write "unknown", even if i run it on real mobile phone.
    I am new to QML, so thanks for your answers!



  • It seems you are getting your technologies mixed up. The example you run is for the accelerometer (movement) but you are talking about a temperature sensor. Just adding bits of code is not going to make code run, there is a little more to it than that.


Log in to reply