在编译 Log4Qt 时报错:
.\log4qt\dailyfileappender.cpp:109: error: invalid operands to binary expression ('QString' and 'QString')
报错的代码如下:
const QRegularExpression creationDateExtractor(
fi.baseName() % QStringLiteral("(.*)") % QStringLiteral(".") % fi.completeSuffix());
类似的写法该文件中还有多处,比如:
QString DailyFileAppender::appendDateToFilename() const
{
QFileInfo fi(mOriginalFilename);
return fi.absolutePath() % QStringLiteral("/") % fi.baseName() % mLastDate.toString(mDatePattern) % QStringLiteral(".") % fi.completeSuffix();
}
Qt 半路出家,不是太熟悉,谢谢大家了!
1
xfcy 2021-02-24 20:57:44 +08:00
QStringBuilder uses expression templates and reimplements the '%' operator so that when you use '%' for string concatenation instead of '+', multiple substring concatenations will be postponed until the final result is about to be assigned to a QString. At this point, the amount of memory required for the final result is known. The memory allocator is then called once to get the required space, and the substrings are copied into it one by one.
文档中的原话。 https://doc.qt.io/qt-5.15/qstring.html |