This could fail for symlinks where one of testDir and dir are referring to a symlink or not. Also if paths are relative or have . or .. in them. I realize these cases aren't likely to happen but it's best to be resilient to them.

I think this works better:
```
QDir test(testDirStr);
test = test.canonicalPath();
QDir dir(dirStr);
dir = dir.canonicalPath();

while (test.cdUp()) {
  // A parent of test is equal to dir.
  if (dir == test) {
    return true;
  } 
}
return false;
```