Qt World Summit: Submit your Presentation

Share file

  • Hi!

    I wrote an app (with a lot of help from many guys here!) that records an audio file.

    Now I need to allow the access to the file outside the application private directories, so that the user can, for instance, send it by email to someone else.

    An important detail is that I tried to save the file in all the values of
    enum QStandardPaths::StandardLocation, but only QStandardPaths::TempLocation worked, in Android as well as in iPhone.

    Does anyone have an idea of how can I do that?


  • Hi!

    I do not know the specification of Android or iPhones, but you may have a look at the output of the standard-paths provided by Qt.


    QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
    if ( !dir.exists() ) {
    QString theDataDir =  QStandardPaths::writableLocation(QStandardPaths::DataLocation);
    qDebug() <<  theDataDir;

    I'm using this path for my apps on linux-based systems. Well, my tries, not apps...but anyway it works :)

  • Tschikkn,

    Thanks for your time!

    What a coincidence! I was reading (again) the help for QDir, and I saw that the directory may not exist yet. So I tried the almost exact the same code you suggested, and now the audio file is being recorded at QStandardPaths::MusicLocation.

    That`s great!

    However, I still have the problem of accessing the file through another application... any ideas?


  • Hi!

    Could you specify "problem of accessing the file"? What exactly does not work as expected? Try to open it with QFile to get an error message.

    Does the other application use the same user-rights as your first one?

  • Thanks again for your time, Tschikkn!

    The audio file is now being saved at QStandardPaths::MusicLocation, but, AFAIK, no other app can access this file. Well, at least the audio player I tried did not "see" it.

    So, my problem is: how to allow another app, like Telegram, GMail, etc., to access this file?


  • As already mentioned I do not know the environments you are working in. But it sounds like a permission problem or an incorrect file.

    If you do have terminal access to your android device you could try to get these informations with

    ls -lha /path/to/file/audiofile.extension

    Giving an output like
    -rw-rw-r-- 1 tschikkn tschikkn 0 Sep 30 23:41 test.file
    See archwiki:File permissions for more info.

    And there are perhaps informations on it using

    file /path/to/file/audiofile.extension

    Without terminal access you may run these commands through QProcess.

    I hope there's enough linux in android to give an output :) Perhaps another member could help you more.

  • I wrote a piece of code to copy the file to QStandardPaths::DownloadLocation, and there were no errors, but still no app, either in Android or iPhone can access the file.

Log in to reply