Dois-je utiliser QThread ou autre ?
Bonsoir,
Je ne sais pas vraiment comment m' y prendre, en ajoutant ceci (cf processinfo.cpp) toute l' interface qml est ralentie. je fais un appel sur le return toutes les 2-3 secondes dans qml.
Le simple fait d' ajouter cela fait passer la consomation cpu de 0-1% à 2% constant.
processInfo.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| QByteArray PROCESSInfo::processTOP()
{
QProcess p(this);
p.start("sh", QStringList() << "-c" << "top -b -n 1 | awk '{print $9, $10, $1, $12}' | head -n 16 | tail -n 10");
if (!p.waitForFinished(1000))
return QByteArray("error");
QStringList list = QString::fromLatin1(p.readAllStandardOutput()).split("/n");
QString result;
foreach(QString s, list) {
result.append(s.split(" ").join(" - ")).append("\n");
}
return result.toLatin1();
} |
main.cpp
(il se trouve à la ligne 81)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| Q_DECL_EXPORT int main(int argc, char *argv[])
{
//QApplication::setGraphicsSystem("raster"); // Use "raster" for systems not supporting "openvg" or "opengl"
QScopedPointer<QApplication> app(createApplication(argc, argv));
SysTrayIcon execSystray;
CPULoad execProcess;
CPUInfo execCPUinfo;
MemInfo execMem;
SENSORStemp execTemp;
HDDInfo execHdd;
GetNetInfo execNet;
MusicInfo execMusic;
PROCESSInfo execProcessus;
//execProcessus.start();
//execProcessus.thread()->currentThreadId();
//execProcessus.wait();
QmlApplicationViewer viewerClock;
viewerClock.setStyleSheet("background:transparent"); //remove background
viewerClock.setAttribute(Qt::WA_TranslucentBackground); //background transparant
viewerClock.setWindowFlags(Qt::FramelessWindowHint); //remove borders
viewerClock.rootContext()->setContextProperty("loadsystray", &execSystray);
viewerClock.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewerClock.setMainQmlFile(QLatin1String("qml/conkycloneqml/content/WidgetClock.qml"));
viewerClock.move(0, 20);
viewerClock.showExpanded();
QmlApplicationViewer viewerCpu;
viewerCpu.setStyleSheet("background:transparent"); //remove background
viewerCpu.setAttribute(Qt::WA_TranslucentBackground); //background transparant
viewerCpu.setWindowFlags(Qt::FramelessWindowHint); //remove borders
viewerCpu.rootContext()->setContextProperty("loadcpu", &execProcess);
viewerCpu.rootContext()->setContextProperty("loadcpuinfo", &execCPUinfo);
viewerCpu.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewerCpu.setMainQmlFile(QLatin1String("qml/conkycloneqml/content/WidgetCpu.qml"));
viewerCpu.move(0, 200);
viewerCpu.show();
QmlApplicationViewer viewerMem;
viewerMem.setStyleSheet("background:transparent"); //remove background
viewerMem.setAttribute(Qt::WA_TranslucentBackground); //background transparant
viewerMem.setWindowFlags(Qt::FramelessWindowHint); //remove borders
viewerMem.rootContext()->setContextProperty("loadmem", &execMem);
viewerMem.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewerMem.setMainQmlFile(QLatin1String("qml/conkycloneqml/content/WidgetMem.qml"));
viewerMem.move(0, 380);
viewerMem.showExpanded();
QmlApplicationViewer viewerHdd;
viewerHdd.setStyleSheet("background:transparent"); //remove background
viewerHdd.setAttribute(Qt::WA_TranslucentBackground); //background transparant
viewerHdd.setWindowFlags(Qt::FramelessWindowHint); //remove borders
viewerHdd.rootContext()->setContextProperty("loadhdd", &execHdd);
viewerHdd.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewerHdd.setMainQmlFile(QLatin1String("qml/conkycloneqml/content/WidgetHdd.qml"));
viewerHdd.move(0, 560);
viewerHdd.showExpanded();
QmlApplicationViewer viewerNet;
viewerNet.setStyleSheet("background:transparent"); //remove background
viewerNet.setAttribute(Qt::WA_TranslucentBackground); //background transparant
viewerNet.setWindowFlags(Qt::FramelessWindowHint); //remove borders
viewerNet.rootContext()->setContextProperty("loadnet", &execNet);
viewerNet.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewerNet.setMainQmlFile(QLatin1String("qml/conkycloneqml/content/WidgetNet.qml"));
viewerNet.move(0, 740);
viewerNet.showExpanded();
QmlApplicationViewer listTest;
listTest.setStyleSheet("background:transparent"); //remove background
listTest.setAttribute(Qt::WA_TranslucentBackground); //background transparant
listTest.setWindowFlags(Qt::FramelessWindowHint); //remove borders
listTest.rootContext()->setContextProperty("loadnet", &execNet);
listTest.rootContext()->setContextProperty("loadtemp", &execTemp);
listTest.rootContext()->setContextProperty("loadhdd", &execHdd);
listTest.rootContext()->setContextProperty("loadcpuinfo", &execCPUinfo);
listTest.rootContext()->setContextProperty("loadmusicinfo", &execMusic);
listTest.rootContext()->setContextProperty("loadprocessus", &execProcessus);
listTest.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
listTest.setMainQmlFile(QLatin1String("qml/conkycloneqml/content/ViewDrag.qml"));
// viewerNetStat.move(20, 200);
listTest.showExpanded();
return app->exec();
} |
WidgetMenu2.qml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Timer {
running: true
repeat: true
interval: 3000
onTriggered: processus.text = loadprocessus.processTOP()
}
Text {
id: processus
x: 40
y: 40
width: 240
height: 360
color: "#969696"
font.pixelSize: 8
opacity: 1
font.family: "DejaVu Sans"
//text: loadprocessus.processTOP()
z: 1
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignTop
} |
Auriez vouz une idee de comment m' y prendre?
J' ai regardé du coté de QThread mais je m' y perd sur la facon d envoyer ca à qml.
Cordialement.