working with files on Android

53 views
Skip to first unread message

Dmitriy Makarov

unread,
Jan 18, 2018, 3:57:17 AM1/18/18
to android-qt
i've written a program for windows, not i'm trying to port it on Android, it has settings file, how can i work with it on Android?

BogDan Vatra

unread,
Jan 18, 2018, 4:01:52 AM1/18/18
to android-qt
If you're using QSettings, it just work.

Yours,
BogDan.

2018-01-18 10:57 GMT+02:00 Dmitriy Makarov <dragef...@gmail.com>:
> i've written a program for windows, not i'm trying to port it on Android, it
> has settings file, how can i work with it on Android?
>
> --
> You received this message because you are subscribed to the Google Groups
> "android-qt" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-qt+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Dmitriy Makarov

unread,
Jan 18, 2018, 6:21:50 AM1/18/18
to android-qt
If you're using QSettings, it just work.

yes, i'm using QSettings
void Settings::read_settings()
{
    QString name = qApp->applicationDirPath() + QDir::separator() + settingFile;
    QSettings setting_file(name, QSettings::IniFormat);
   
...........
}

void Settings::write_settings()
{
    QString name = qApp->applicationDirPath() + QDir::separator() + settingFile;
    QSettings setting_file(name, QSettings::IniFormat);
    if (setting_file.isWritable())
    {
   
............
   
}
}
but as i know there is no
applicationDirPath
in Android

BogDan Vatra

unread,
Jan 18, 2018, 6:34:39 AM1/18/18
to android-qt
Use just
QSettings setting_file;

Dmitriy Makarov

unread,
Jan 18, 2018, 6:50:15 AM1/18/18
to android-qt
it works that way:
void Settings::read_settings()
{
#ifdef Q_OS_WIN32
    QString name = qApp->applicationDirPath() + QDir::separator() + settingFile;
#endif
#ifdef Q_OS_ANDROID
    QString name = "assets:/" + settingFile;
#endif
    QSettings setting_file(name, QSettings::IniFormat);
   
...........
}

void Settings::write_settings()
{
#ifdef Q_OS_WIN32
    QString name = qApp->applicationDirPath() + QDir::separator() + settingFile;
#endif
#ifdef Q_OS_ANDROID
    QString name = "assets:/" + settingFile;
#endif

BogDan Vatra

unread,
Jan 18, 2018, 7:16:12 AM1/18/18
to android-qt
assets are read-only resources ! so I do not suggest you to use them.
Reply all
Reply to author
Forward
0 new messages