How to get user's download folder in Qt? - qt

How do I get the standard system / user paths in Qt?
What I really need is to get the location of the user's Downloads folder.

In Qt 4, there is QDesktopServices providing some user paths:
https://doc.qt.io/qt-4.8/qdesktopservices.html#StandardLocation-enum
It has e.g. Desktop and Documents but no specific Downloads folder.
In Qt 5, use QStandardPaths:
const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);

You can use QDir::homePath() to get a QString to the home directory of the current user's profile but I'm not sure that there is a "standard" download directory identified by the OS.

With Qt 5.15.0, on a fr-FR Linux (Manjaro) :
qDebug() << QStandardPaths::displayName(QStandardPaths::DownloadLocation);
returns :
"Téléchargement"
This is not the actual French "DownloadLocation" folder name, which is called "Téléchargements", with a plural s, because this folder usually contains more than one downloaded file. Btw, English localization seems to be "~/Downloads", according to Qt 5 online help, with the expected plural s.
Therefore, QStandardPaths::DownloadLocation is unreliable in French. If someone may file and follow the bug at Qt, this might help !

Related

How to have QFileSelector select files based on device

Reading the QFileSelector Class documentation, I see:
QFileSelector is a convenience for selecting file variants based on platform or device characteristics
I am successfully using the related QQmlFileSelector class to select a set of files based on if I am building for Mac (a +mac directory).
However, I need to also build for Ubuntu Desktop and an embedded device which is also running Ubuntu. Therefore, I cannot just add another platform directory directly related to ubuntu.
Based on the reference to device characteristics in the documentation, I figure I can create a folder directly related to the device.
I have a Kit setup for the embedded device and a Device used by the kit named Ansible.
Can anyone provide further details on how I can have QQmlFileSelector select the files in a + folder when building for Ansible?
You can add your own selectors using any name you want. Here's an example:
QQmlFileSelector *selector = QQmlFileSelector::get(engine);
QStringList options;
if (usingAnsible())
{
options << "ansible";
}
else
{
options << "x86";
}
selector->setExtraSelectors(options);
Then your files would be in either the +ansible or +x86 directory.

Setting custom local storage Path in QML

I m trying to put a custom path in QML file but can't get it done.
I'm trying to get de db in a shared folder where i'm willing to put the DB so any person who has the program can acces to data.
I'm using Sqlite and Qt Creator 5.7 but not a lot of info about this.
You can simply COPY the database from its default path. Typically that is located (In windows anyways) at
C:\Users\<username>AppData\Local\<program name>\QML\OfflineStorage\Databases
and on Mobile devices it is stored in a similar place --
on android its in a sub folder of:
/data/data/<Program Name>
On *nix it is located:
/home/<user>/.local/share/[ProjectName]/QML/OfflineStorage/Databases

Qt WinRT Folder Permission Issue

Hi I already posted a question Qt WinRT App cannot access file permission denied regarding ffmpeg library and video file read, and now I think the entire project should have some permission to access/modify the files system in WinRt Qt App.
Below is a simple code which create a directory if not exist, bu this also failing always, so I think it permission issue, and there are something should add on AppxManifest.xml.
QString dirname = QDir::homePath()+"/test";
QDir dir(dirname);
if(!dir.exists())
{
//dir.mkdir(dirname);
if(false==dir.mkpath(dirname)){
qDebug()<<"Creating "<<dirname<<" failed...";
}
}
Anyone have faces this before, any suggestion, tips ..
Thanks in Advance.
Haris
WinRT as a platform will not allow you to "simply" create files outside the sandbox of the application. There are certain directories you can use (Media, Photos, ...) in case you have the correct capability set. And even then you will only be allowed to open/create/read/write files selected by the file picker.

How to open a particular file with my QT application on Mac when i double click the file?

I'm finding no way how to open a specific file format which can be opened by my Qt app automatically(when i double click the file).Please let me know how to do this.
Thanks!
You need to set up your Information Property List file (Info.plist) in your application bundle to identify files that can be opened by your app. See http://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Introduction/Introduction.html
Specifically, set the CFBundleDocumentTypes key: add items, the file extension and the role of your application (does it edit, view, etc the file).
After you have done this, finder will need to reload the plist. Then you will be able to choose to open files of that type with your application.
In your application, you will need to subclass QApplication and set up a response for QEvent::FileOpen. More information on doing that was given in Qt Quarterly Issue 18.

How to specify the location for FileReference.browse() in Flex

I have a requirement to select a file from fileReference.browse(), but I want to browse a file to specific location say D:\Dir\file instead of the OS specific (The dialog box is native to the user's operating system).
Is it possible?
Thanks in Advance-
Since you're using File, I'm assuming you're using the Air runtime. To do this, you just need to set the path in the file constructor before you browser; like this:
var file:File = new File(somePath);
file.browse();
The only problem with this is that if you set it as an absolute path (like say, "c:\Users\SomeUser"), it might not work on Macs or Linux computers. Be sure to use some of the File class' built in static properties when you can, like these:
File.applicationStorageDirectory—a storage directory unique to each installed AIR application
File.applicationDirectory—the read-only directory where the application is installed (along with any installed assets)
File.desktopDirectory—the user's desktop directory
File.documentsDirectory—the user's documents directory
File.userDirectory—the user directory

Resources