2

I am trying to get application data folder location under Linux using Qt's storageLocation function:

QDesktopServices::storageLocation(QDesktopServices::DataLocation)

But this function returns path with two slashes at the end:

 /home/user/.local/share/data//

Two slashes at the end of path looks very strange for me. Is this normal? Or this is bug in Qt? My Linux is Ubuntu. Qt version is 4.8.1.

4

3 に答える 3

3

This is a bug in Qt (see bug report). However, it happens only if you didn't set your app's name and organization name. You should set them using QApplication::setApplicationName and QApplication::setOrganizationName.

The chop solution you've accepted earlier is bad for two reasons. The first, if this bug is fixed, your code could be broken. Who knows how many slashed will be here in the next version (maybe 0). I'd suggest to use the following to remove double slash:

QString s = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
s = QDir(s).absolutePath();

But it's more important that the /home/user/.local/share/data/ location is still invalid. You need to set application and organization names if you want to get proper location. Simple removing trailing slash doesn't fix anything, it's just a dirty hack.

于 2013-06-14T09:53:25.773 に答える
1

I know it's an old question but QDesktopService::dataLocation have the following structure <user data location>/<application name>/.

Under linux, the user data location is $HOME/.local/share/data/.

The application name is set via the QCoreApplication::setApplicationName() method, I guess you do not set it, which explains why you have two trailing slashes.

于 2013-06-14T09:35:39.897 に答える
0

No its not only you its same on here. you just need to chop the last character

QString s = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
s.chop(1); 
于 2012-08-14T15:48:44.977 に答える