我已经习惯了使用QStringList() << "a" << "b"
成语快速构建QStringList中传递给函数,但是当我试了一下QXmlStreamAttributes
,它没有工作。
此代码编译:
QXmlStreamAttributes attributes;
attributes << QXmlStreamAttribute("a", "b");
writer.writeAttributes(attributes);
但是这一次失败:
writer.writeAttributes(QXmlStreamAttributes() << QXmlStreamAttribute("a", "b"));
它失败,错误:
C:\Workspace\untitled5\mainwindow.cpp:18: error: C2664: 'QXmlStreamWriter::writeAttributes' : cannot convert parameter 1 from 'QVector<T>' to 'const QXmlStreamAttributes &'
with
[
T=QXmlStreamAttribute
]
Reason: cannot convert from 'QVector<T>' to 'const QXmlStreamAttributes'
with
[
T=QXmlStreamAttribute
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
另一件事我注意到:
此代码编译:
QVector<QXmlStreamAttribute> v1 = (QVector<QXmlStreamAttribute>() << QXmlStreamAttribute("a", "b"));
但是这一次没有,即使QXmlStreamAttributes从继承QVector<QXmlStreamAttribute>
QXmlStreamAttributes v2 = (QXmlStreamAttributes() << QXmlStreamAttribute("a", "b"));
它失败,出现同样的错误。
任何想法,为什么出现这种情况?