带有QList <qstring>功能的QT应用程序&#34;追加&#34;

时间:2018-05-29 14:10:15

标签: c++ q qregularexpression

我尝试使用以下代码返回从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;

我怎样才能让它发挥作用,我已尝试投入多种类型。

2 个答案:

答案 0 :(得分:5)

请尝试以下代码:

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;

因为有可能在c ++中重载()之类的运算符,所以编译器在没有参数和括号运算符的构造函数之间产生差异是非常复杂的。 因此,如果您想要在没有任何参数的情况下调用构造函数,请不要使用括号Qlist<QString> myList;

您只能在使用运算符QList<QString> *myList = new QList<QString>()时添加括号。

括号运算符用于在C ++中创建可调用对象,如果您想了解更多关于它的信息,可以查看此link

答案 1 :(得分:3)

Set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set originalMsg = Session.GetRDOObjectFromOutlookObject(Application.ActiveExplorer.Selection(1))
set newMsg = Session.GetDefaultFolder(olFolderDrafts).Items.Add
'copy the message and clear out recipients
originalMsg.CopyTo(newMsg)
newMsg.Recipients.Clear
newMsg.Recipients.Add "xxx@xxx.net"
newMsg.Save
'now reopen the message in OOM and diplay it. Or you can use newMsg.Display
set myForward = Application.Session.GetItemFromID(newMsg.EntryID)
myForward.Display

这实际上是一种功能。对于变量,您必须省略括号;但这很令人困惑,因为你通常使用括号将参数传递给构造函数。

应该是:

QList<QString> list();