So, where exactly is the problem. Use QDir and use QDir::cdUp() till both are the same. You need of course to count how often you cd up. Or simply split on / and subtract one from the other.
So, where exactly is the problem. Use QDir and use QDir::cdUp() till both are the same. You need of course to count how often you cd up. Or simply split on / and subtract one from the other.
My first thought too was to count slashes, but you have to be careful about terminal slashes (that is, "/" is the last character in the string).
Probably the best thing to do is strip or otherwise take into account any terminal slashes before doing your counting. It's not a problem if your root and target directories both end in "/" or both don't end in "/" but you'd get the wrong answer if one ended in "/" and the other didn't, as in your example.
So run both strings through QDir::cleanPath before counting the slashes![]()
Thank to all
Franco Amato
Bookmarks