Когда я читал исходный код Qt5.15.2, касающийся реализации метода mkpath в классе QDir, я не понял следующие строки кода.
Код: Выделить всё
/*!
Returns the path name of a file in the directory. Does \e not
check if the file actually exists in the directory; but see
exists(). If the QDir is relative the returned path name will also
be relative. Redundant multiple separators or "." and ".."
directories in \a fileName are not removed (see cleanPath()).
\sa dirName(), absoluteFilePath(), isRelative(), canonicalPath()
*/
QString QDir::filePath(const QString &fileName) const
{
if (treatAsAbsolute(fileName))
return fileName;
const QDirPrivate* d = d_ptr.constData();
QString ret = d->dirEntry.filePath();
if (fileName.isEmpty())
return ret;
#ifdef Q_OS_WIN
if (fileName.startsWith(QLatin1Char('/')) || fileName.startsWith(QLatin1Char('\\'))) {
// Handle the "absolute except for drive" case (i.e. \blah not c:\blah):
const int drive = drivePrefixLength(ret);
return drive > 0 ? ret.leftRef(drive) % fileName : fileName;
}
#endif // Q_OS_WIN
if (ret.isEmpty() || ret.endsWith(QLatin1Char('/')))
return ret % fileName;
return ret % QLatin1Char('/') % fileName;
}
Код: Выделить всё
return ret % fileName;
return ret % QLatin1Char('/') % fileName;
Я написал следующий метод в своем собственном коде для тестирования, но он не скомпилируется
Код: Выделить всё
QString test()
{
QString ret = "12";
QString fileName = "34";
return ret % fileName;
}
Код: Выделить всё
Error C2676: Binary "%":"QString” does not define the operator or the conversion to the type that the pre-defined operator can receive
Источник: https://stackoverflow.com/questions/781 ... ring-in-qt