標籤:debug log app trre 樣本 大小 widget rip 裝置
首先得在pro檔案中加入QT+=script
然後匯入相應的標頭檔
include <QStringList>#include <QtScript/QScriptEngine>#include <QtScript/QScriptValue>#include <QtScript/QScriptValueIterator>
接下來便可使用相應的API了
範例程式碼:
QString strJson = "{ \"student\":[{\"Name\":\"ccf\",\"Math\":\"95\", \"Chinese\":\"84\"}, {\"Name\":\"zhangsan\",\"Math\":\"75\", \"Chinese\":\"70\"}]}"; QScriptEngine engine; QScriptValue sc = engine.evaluate("value=" + strResult); if (sc.property("dan").isArray()) //解析json數組 { QScriptValueIterator it(sc.property("dan")); while(it.hasNext()) { it.next(); if (!it.value().property("type").toString().isEmpty()) { qDebug() << "type :" << it.value().property("type").toString(); qDebug() << "data :" << it.value().property("data").toString(); receMsg = it.value().property("data").toString(); qDebug() << "user :" << it.value().property("use").toString(); QDesktopWidget* desktopWidget; //擷取電腦裝置 QRect screenRect; desktopWidget = QApplication::desktop(); //擷取電腦裝置 screenRect = desktopWidget->screenGeometry(); //擷取案頭大小的矩形 Danmu * danmu = new Danmu(NULL,receMsg,"Red",1,screenRect); qDebug()<<"x"<<danmu->getPosX()<<" y"<<danmu->getPosY(); } } }
關於QT5使用QtScript解析QJsonArray數組的問題