Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Finding config files in Android runtime deployments (Qt6.9.1)
Forum Updated to NodeBB v4.3 + New Features

Finding config files in Android runtime deployments (Qt6.9.1)

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 3 Posters 197 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SMF-QtS Offline
    SMF-QtS Offline
    SMF-Qt
    wrote last edited by SMF-Qt
    #1

    I am trying to access a simple config file (Config.conf) from my Qt6 Android App.

    It was suggested I add:

    android {
    my_files.path = /assets
    my_files.files = $$PWD/etc/Config.conf
    INSTALLS += my_files
    }

    To my QtTest4.pro file this results in the file being included in my Apk file, if I unpack the Apk file (/tmp/MyApp) and do a file search I get:

    find . -name Config.conf
    ./assets/Config.conf

    If I grep through the files under /tmp/MyApp I find:

    ./META-INF/MANIFEST.MF:Name: assets/Config.conf
    ./META-INF/KEY1.SF:Name: assets/Config.conf

    So I belive my config file is part of the Apk file for deployment.

    When I debug my App at the point of opening the config file my working directory is:

    "/data/data/com.home.QtTest4/files"

    But the open always returns "no such file or directory" I have tried various prefixes for my config file but non have worked.

    My question is:

    Relative to my working directory where is the Config.conf file located ?

    Thanks

    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote last edited by
      #2

      Hi @SMF-Qt,

      please format your code properly, using the </> code tags.
      Please also post the code around and including the call to fopen().

      Software Engineer
      The Qt Company, Oslo

      SMF-QtS 1 Reply Last reply
      0
      • Axel SpoerlA Axel Spoerl

        Hi @SMF-Qt,

        please format your code properly, using the </> code tags.
        Please also post the code around and including the call to fopen().

        SMF-QtS Offline
        SMF-QtS Offline
        SMF-Qt
        wrote last edited by SMF-Qt
        #3

        @Axel-Spoerl

        This is the essence of the code I am using errno is returning 2 (no such file or directory).
        I have tried adding various directory prefixes but no luck yet, works fine on linux.

        ...
        
        const char *name="Config.conf";
        
        ...
        int fd=open(name, O_RDONLY, 0640);
        if (fd<0)
           return errno;
        ...
        
        
        

        On linux I use "/etc/connect/Config.conf" but that is not relevant under Android.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote last edited by SGaist
          #4

          Hi,

          With QFile you could use the assets:/ prefix and it would get you what you want.
          See here.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          SMF-QtS 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            With QFile you could use the assets:/ prefix and it would get you what you want.
            See here.

            SMF-QtS Offline
            SMF-QtS Offline
            SMF-Qt
            wrote last edited by
            #5

            @SGaist

            Thanks I assume thats assets not asset. I will create a QFile with that file path structure and debug the QFile open and see what it decodes to at the lowest level.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote last edited by
              #6

              Correct (and fixed) but don't assume, check the doc linked ;-)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • SMF-QtS Offline
                SMF-QtS Offline
                SMF-Qt
                wrote last edited by
                #7

                I did :-)

                1 Reply Last reply
                0
                • Axel SpoerlA Offline
                  Axel SpoerlA Offline
                  Axel Spoerl
                  Moderators
                  wrote last edited by
                  #8

                  First and foremost, as already said by @SGaist , I would really recommend to use the resource file system instead of trying to deploy files manually.

                  This can be confusing at times. The Swiss army knife to figure out how to access your resources is a three-liner.
                  You can add it to your main.cpp in order to print a list of all existing resource files:

                  QDirIterator it(":", QDirIterator::Subdirectories);
                  while (it.hasNext())
                      qInfo() << it.next();
                  

                  Software Engineer
                  The Qt Company, Oslo

                  SMF-QtS 1 Reply Last reply
                  0
                  • Axel SpoerlA Axel Spoerl

                    First and foremost, as already said by @SGaist , I would really recommend to use the resource file system instead of trying to deploy files manually.

                    This can be confusing at times. The Swiss army knife to figure out how to access your resources is a three-liner.
                    You can add it to your main.cpp in order to print a list of all existing resource files:

                    QDirIterator it(":", QDirIterator::Subdirectories);
                    while (it.hasNext())
                        qInfo() << it.next();
                    
                    SMF-QtS Offline
                    SMF-QtS Offline
                    SMF-Qt
                    wrote last edited by
                    #9

                    @Axel-Spoerl said in Finding config files in Android runtime deployments (Qt6.9.1):

                    QDirIterator it(":", QDirIterator::Subdirectories);
                    while (it.hasNext())
                    qInfo() << it.next();

                    Thanks for that but I see files I have in my images directory and stuff from the qt project but nothing from :/assets, but as I said the file is there if I unpack the Apk file.
                    Do I need to add something to the AndroidManifest.xml or my qrc file ?

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved