【发布时间】:2016-01-21 00:35:27
【问题描述】:
我在 Qt 中使用 SQLite 数据库。在用信息填充 QTableWidget 时,我想检查作为 QVariant 接收的值是整数、双精度还是字符串:
// query something here, put in in var named 'query'
while(query.next()){
// insert new row
for (int i=0; i<columnCount; i++){
if(query.value(i).toInt()!=0){
//add integer table item with special sorting/formatting
}else if(query.value(i).toDouble()!=0){
//add double table item with special sorting/formatting
}else {
//add standard qt table item
}
}
}
问题是在使用 toInt() 时 double 会被转换为整数,反之亦然,这就是为什么所有数值都被视为整数或都被视为双精度数的原因,这取决于你使用哪一个先测试一下。
是否有可能正确检查数字是双精度数还是整数?
【问题讨论】: