I have a qt app, when the user wants to open a file I use the QFileDialog::getOpenFileName.
The path returned is /run/user/1000/doc/39face4d/myFile.txt instead of /home/user/Documents/myFile.txt
How do I get the “User friendly” path? Am I missing something in the yaml?
I’m not sure what’s causing this but it looks like your application is using $XDG_RUNTIME_DIR instead of $HOME. Is there anything in Qt docs about the functions you’re using using $XDG_RUNTIME_DIR?
Well… actually what I do is simply this:
QString fileName = QFileDialog::getOpenFileName( this, QString(), "~", "*.*");
This opens the Choose File Dialog…
I select the file /home/user/Documents/myFile.txt (already exists).
The value of fileName is “/run/user/1000/doc/6cdffe5/myFile.txt”
instead of “/home/user/Documents/myFile.txt”
I could not find anything in the docs… expecially because docs related to Qt and Snap are a little bit difficult to parse…
Hmm, sorry I don’t know any more about Qt to be of much help, hopefully someone else will see this and provide some assistance.
I believe the file is made available though the document portal, which is a fuse filesystem under
/run/user/<uid>/doc. So what you get is really
myFile.txt from the original path, and an external program makes sure that content written there ends up in
Probably @jamesh knows more about this.
This does indicate that Qt is using xdg-desktop-portal to show the file chooser here. Note that reading from the
/run/usr/... path provided will return the contents from the file in
~/Documents, and writes will also be directed to the location you picked. In the vast majority of cases, this proxying is harmless, and gives the user fine grained control over what documents they make available to the confined application.
I am slowly working on some improvements to xdg-desktop-portal/xdg-document-portal that should allow it to avoid proxying files we’re sure the snap can access (e.g. non-hidden files in the user’s home directory if the snap plugs the
home interface). That is still a work in progress though.
What I do in my snap is to dump the procompiled libs from Qt 5.14. Now my considerations are the following:
- I am forgetting to pull a necessary but not required lib
- precompiled Qt libs are not totally compatible with snapcraft.
I will dig another couple of days in the hope to find a solution… otherwise it will be “Yet another good but a little buggy linux application”
AFAIU this is correct and expected behavior for a confined application using the document portal, be it a snap or a flatpak.
Not really: if I snap my app in the “traditional way”, using the qmake plugin and the qt 5.9 libs that comes with snap, the dialog works fine…
The problem is that for my app I need a couple of the new features that came in the last 3 years… so basically the question become: how do I create a snap for a Qt 5.14.1 application the right way??? Do you know of any example or tutorial?
Ok… I did it myself:
It’s buggy… but for some other projects it may work.
I have this same issue, and since the file I’m accessing is a script (that runs confined in the snap environment) I get a permission issue.
If I set the path manually with /home//… the script runs properly.
The snap has home access.
Is there an option to tell the portal to allow execute permissions to the loaded files?