Qt equivalent of PathAppend?

前端 未结 1 713
误落风尘
误落风尘 2020-12-03 21:50

PathAppend is a useful winapi function that lets you append one path to another while taking care of any trailing backslashes (or lack of them).

Meaning that appendi

相关标签:
1条回答
  • 2020-12-03 22:12

    There is not that function but QDir::cleanPath() will handle everything you need, you just have to concatenate paths:

    QString appendPath(const QString& path1, const QString& path2)
    {
        return QDir::cleanPath(path1 + QDir::separator() + path2);
    }
    

    I used QDir::separator() instead of raw "/" but it's not mandatory because QT internally translate that separator to the native one (if needed, see Cross-platform way of constructing an FS path with Qt).

    Note that (for whom with a .NET background) there is another similar function: Path.Combine(), it behaves somehow similar to PathAppend() but it's different. See Is there a QPath::Combine()? for a QT emulation of its behavior (and for a slightly more detailed outlining of their differences).

    0 讨论(0)
提交回复
热议问题