[SOLVED] How do I print processor temperature in qml file as text?
-
wrote on 4 Sept 2015, 03:32 last edited by Epidemic 9 Jul 2015, 10:22
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 }
-
wrote on 4 Sept 2015, 05:16 last edited by
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.
-
wrote on 7 Sept 2015, 10:22 last edited by
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();
}
-
wrote on 8 Sept 2015, 20:18 last edited by
You can move most of that into QML by using this approach:
-
wrote on 13 Sept 2015, 07:29 last edited by
YES bro, you are the king! That's EXACTLY what I want! :)
I'm sorry for the late answer.
1/5