user9900698
user9900698

Reputation:

QFileDialog not resolving symlinks

opt = QFileDialog()
folder = QFileDialog.getExistingDirectory(self, "choose folder", path, options=opt.ShowDirsOnly)

This is my code to select folders in a file browser. By default it should be able to resolve symlinks. But i do not see this behavior.

The folder I select is /home/user/abc which is a symbolic link to /home/user/xyz.

>> print(f'Folder is: {folder}')
Folder is: /home/user/abc
>> print(f'Folder is: {os.path.realpath(folder)}')
Folder is: /home/user/xyz

Is it possible to get the actual path (/home/user/xyz) from getExistingDirectory() method without using os.path.realpath() later?

Upvotes: 1

Views: 302

Answers (1)

eyllanesc
eyllanesc

Reputation: 243897

It is not possible in Linux, in windows the symbolic link is resolved.

QFileDialog uses a QFileSystemModel as the QTreeView model, and enables by default the resolveSymlinks property that does that job but as the docs points out:

resolveSymlinks : bool

This property holds whether the directory model should resolve symbolic links

This is only relevant on Windows.

By default, this property is true.

Access functions:

bool resolveSymlinks() const
void setResolveSymlinks(bool enable)

(emphasis mine)

Upvotes: 1

Related Questions