[英]How do you convert a single element of a double array to a QString?
我的代碼是這樣的:
void Tests::writeResultsFile(QString &logTestResults, QString
&combinedResultsS, double &combinedResultsN, QString &deviceId)
{
QFile file(logTestResults); //open test results file
QString convertedNumbersResults[12];
for (int i = 0; i < 12; i++)
{
//below line doesn't work as is
convertedNumbersResults[i] = QString::number(combinedResultsN[i],'f',2);
}
file.remove();
}
file.close();
}
編譯時收到此錯誤:“C2109:下標需要數組或指針類型”
弄清楚了這個問題,正如@eyllanesc 雄辯而禮貌地指出的那樣,我錯誤地傳遞了我的數組。
正確的方法:
void Tests::writeResultsFile(QString &logTestResults, QString
combinedResultsS[2], double combinedResultsN[12], QString &deviceId)
{
QFile file(logTestResults); //open test results file
QString convertedNumbersResults[12];
for (int i = 0; i < 12; i++)
{
//below line works now
convertedNumbersResults[i] = QString::number(combinedResultsN[i],'f',2);
}
file.remove();
}
file.close();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.