I am trying to turn a QDir which can contain relative or absolute paths into a list of folders in a QStringList like this:
const QString path = dir.path ();
return path.split (QRegExp ("[\\/]+"), QString::SkipEmptyParts);
This ideally would turn a path like C:\foo\bar into a list of strings "C:", "foo", and "bar"
Is there a better way to do this that is already implemented in Qt?
What you want is:
QDir::toNativeSeparators(dir.path()).split(QDir::separator(),
QString::SkipEmptyParts);
That way you avoid the need for a regexp.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With