我正在从 xml 文件中读取数据并尝试将数据解析为双精度数据。它正在读取数据并在应用程序输出中显示适当的字符串,但不会从字符串转换为双精度。这是进行转换的代码部分。
if ( !(imgDur = QString ( xmlReader->readElementText() ).toDouble()) ){
imgDur = 10;
}
这将返回数字 0。我得到零错误并且代码编译。为什么这行不通?谢谢你的时间。
读取 XML 文件的整个循环
//Parse the XML until we reach end of it
while(!xmlReader->atEnd() && !xmlReader->hasError()) {
// Read next element
QXmlStreamReader::TokenType token = xmlReader->readNext();
//If token is just StartDocument - go to next
if(token == QXmlStreamReader::StartDocument) {
continue;
}
//If token is StartElement - read it
if(token == QXmlStreamReader::StartElement) {
if(xmlReader->name() == "time_delay") {
qWarning() << xmlReader->readElementText(); // OUTPUTS 15
if ( !(imgDur = QString (xmlReader->readElementText()).toDouble() ) ){
qWarning() << "AS AN DOUBLE" << imgDur; // OUTPUTS 0
imgDur = 10;
}
}
if(xmlReader->name() == "value") {
qWarning() << xmlReader->readElementText(); // OUTPUTS 8
}
}
}