c – 具有QList功能的QT应用程序“追加”
作者:互联网
我正在尝试使用以下代码返回从QRegularExpression返回到QList的匹配列表:
QList<QString> list();
QString str ("something by the way");
QRegularExpression reA("pattern");
QRegularExpressionMatchIterator i = reA.globalMatch(str);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
if (match.hasMatch()) {
list.append(match.captured(0));
}
}
return list;
…但它告诉我这个错误:
/home/path/.../file:line# error: request for member 'append' in 'list', which is of non-class type 'QList<QString>()'
list.append(match.captured(0));
/home/path/.../file:line#: error: could not convert 'list' from 'QList<QString> (*)()' to 'QList<QString>'
return list;
我怎样才能使它工作,我试图投入多种类型.
解决方法:
QList<QString> list();
它实际上是一个功能.对于变量,您必须省略括号;但这很令人困惑,因为你通常使用括号将参数传递给构造函数.
它应该是:
QList<QString> list;
// or
QList<QString> list{};
标签:q,c,qregularexpression 来源: https://codeday.me/bug/20190724/1521474.html