今天在序列化一个结构体时,报了一个莫名其妙的bug,结构体内容如下:
struct SampleInfos {
quint32 id;
QString name;
double volume;
quint32 dropletSize;
};
序列化代码如下:
inline QDataStream &operator<<(QDataStream& out, const SampleInfos& info)
{
out << info.id << info.name << info.volume << info.dropletSize;
return out;
}
报错内容如下:
experiment_infos.h:111:36: error: conversion from 'const double' to 'QChar' is ambiguous
qchar.h:96:22: note: candidate constructor
qchar.h:98:22: note: candidate constructor
qchar.h:99:22: note: candidate constructor
qchar.h:100:22: note: candidate constructor
qchar.h:104:22: note: candidate constructor
qchar.h:111:22: note: candidate constructor
qchar.h:662:59: note: passing argument to parameter here
如果把double换成其他类型的就没有问题,后来在头文件加了一行
#include <QDataStream>
问题解决了。