[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 font.family: steelfish.name color: "#ffffff" smooth: true x: 75 y: 20 }
-
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();
}
-
You can move most of that into QML by using this approach: