Important: Please read the Qt Code of Conduct -

[SOLVED] How do I print processor temperature in qml file as text?

  • Hi everyone. I tried to make an application on Raspberry Pi, I want to print the CPU temperature under the settings menu, but I do not know how to do it. Please help...

    The following command shows the temperature; "/opt/vc/bin/vcgencmd measure_temp"

    Text {
        id: text_temperature
        visible: true
        text: "48°C" 	//CPU temperature here.
        font.pixelSize: 21
        color: "#ffffff"
        smooth: true
        x: 75
        y: 20

  • I think you'll need to use QProcess in C++ to run the external command. Then store the result in a property, and you can reference the property directly from QML.

  • I fixed the problem, and now I'm trying to repeat the data at regular intervals.

    int main(int argc, char* argv[])
    QGuiApplication app(argc,argv);
    QQuickView view;

    QObject *parent = 0;
    QString program = "/opt/vc/bin/vcgencmd";
    QStringList arguments;
    arguments << "measure_temp";
    QProcess *myProcess = new QProcess(parent);
    myProcess->start(program, arguments);
    QString result = myProcess->readAllStandardOutput();
    QString subString = result.mid(5,2);
    view.rootContext()->setContextProperty("currentCpuTemp", subString);
    view.resize(848, 480);;
    return app.exec();


  • You can move most of that into QML by using this approach:

  • YES bro, you are the king! That's EXACTLY what I want! :)

    I'm sorry for the late answer.