Why is there no static QDir :: makepath ()?

I know that to create a new path in Qt from a given absolute path, you use QDir::makepath()how dir.makepath(path), as suggested in this question. I have no problem using it and it works great. My question is directed as to why , developers will not provide a static function to call in this way QDir::makepath("/Users/me/somepath/");. I need to create a new instance QDir.

I can only think of two possible reasons:

1. The developers were "lazy" or did not have time, so they did not add, as this is not entirely necessary.

2. The instance QDirbeing called mkpath(path)will also be set to path, so that would be convenient for future use - but I can't seem to find any hints that this is the actual behavior in the docs .

I know that I’m repeating it myself, but again, I do n’t need help on how to do this, but I’m very curious why this should be done that way. Thanks for any reason I might have missed.

+4
source share
1 answer

Let's look at the code of the specified method:

bool QDir::mkdir(const QString &dirName) const
{
    const QDirPrivate* d = d_ptr.constData();

    if (dirName.isEmpty()) {
        qWarning("QDir::mkdir: Empty or null file name");
        return false;
    }

    QString fn = filePath(dirName);
    if (d->fileEngine.isNull())
        return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);
    return d->fileEngine->mkdir(fn, false);
}

Source: http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/io/qdir.cpp#n1381

, :

bool QDir::mkdir(const QString &dirName) const
{
    if (dirName.isEmpty()) {
        qWarning("QDir::mkdir: Empty or null file name");
        return false;
    }

    return QFileSystemEngine::createDirectory(QFileSystemEntry(dirName), false);
}

(. http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/io/qdir.cpp#n681)

-, . , - . ( QDir).

?

(tl/dr): , . API, QDir::makepath(path); QDir().makepath(path); . , , . , , ( ), .

+3

Source: https://habr.com/ru/post/1610635/


All Articles