Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] How do I print processor temperature in qml file as text?

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

Scheduled Pinned Locked Moved QML and Qt Quick
qprocessqmlraspberry piqtquickcpu
5 Posts 2 Posters 4.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • EpidemicE Offline
    EpidemicE Offline
    Epidemic
    wrote on last edited by Epidemic
    #1

    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
        font.family: steelfish.name
        color: "#ffffff"
        smooth: true
        x: 75
        y: 20
    }
    
    1 Reply Last reply
    0
    • X Offline
      X Offline
      xargs1
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • EpidemicE Offline
        EpidemicE Offline
        Epidemic
        wrote on last edited by
        #3

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

        int main(int argc, char* argv[])
        {
        QGuiApplication app(argc,argv);
        QQuickView view;
        view.setResizeMode(QQuickView::SizeRootObjectToView);

        QObject *parent = 0;
        QString program = "/opt/vc/bin/vcgencmd";
        QStringList arguments;
        arguments << "measure_temp";
        
        QProcess *myProcess = new QProcess(parent);
        myProcess->start(program, arguments);
        myProcess->waitForFinished(1000);
        
        QString result = myProcess->readAllStandardOutput();
        QString subString = result.mid(5,2);
        subString.append("°C");
        
        view.rootContext()->setContextProperty("currentCpuTemp", subString);
        view.setSource(QUrl("qrc:/main.qml"));
        view.resize(848, 480);
        view.show();
        
        return app.exec();
        

        }

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xargs1
          wrote on last edited by
          #4

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

          http://www.xargs.com/qml/process.html

          1 Reply Last reply
          1
          • EpidemicE Offline
            EpidemicE Offline
            Epidemic
            wrote on last edited by
            #5

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

            I'm sorry for the late answer.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved