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. Android .txt resource file editing in Qt
Forum Updated to NodeBB v4.3 + New Features

Android .txt resource file editing in Qt

Scheduled Pinned Locked Moved Solved Mobile and Embedded
androidqt qfile
12 Posts 4 Posters 2.9k Views
  • 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.
  • jsulmJ Online
    jsulmJ Online
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #3

    I may be wrong but as far as I know on Android you cannot write in the directory where your app is installed (for security reasons). The qrc file is part of your application, so I guess it will not work this way. You should use a directory where your app has write access.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • M Offline
      M Offline
      monster
      wrote on last edited by
      #4

      I see. So am I able to create a blank file in the application when it starts for the first time and then to edit it when it actually exists in the given location? How should I do it?

      1 Reply Last reply
      0
      • jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #5

        Check this one on Android:

        QString QStandardPaths::writableLocation(StandardLocation type)
        Call it like this:
        QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
        

        More here: http://doc.qt.io/qt-5/qstandardpaths.html

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • M Offline
          M Offline
          monster
          wrote on last edited by
          #6

          Thank you a LOT! Especially for Standard Paths. It works :) I've got last small question. I've noticed that I understand file operation modes wrong. Writing in append mode seems easy. As a ReadOnly mode, I understand the mode in which you start reading the file from the beggining. But now I found that WriteOnly mode erases all file and starts writing from the beginning! Is that right? I thought that WriteOnly opens the file with pointer pointing the beginning of file, and so I thought that writing in that mode allows me to replace previously written characters. I want to find the mode that allows me to change the number at the beginning without writing whole file again...

          jsulmJ 1 Reply Last reply
          0
          • M Offline
            M Offline
            monster
            wrote on last edited by
            #7

            Sorry that I've got even more questions :D

            Can I declare structures with QStrings and then resize them inside that structure? Does structure also resize itself then?

            Am I correct that I don't have to resize the QString when I declare:
            QString valuvalue = somekindofcharorstring;
            ?
            It changes its size automatically, am I right?

            1 Reply Last reply
            0
            • stackprogramerS Offline
              stackprogramerS Offline
              stackprogramer
              wrote on last edited by stackprogramer
              #8

              hi,i offer, you can use xml or json for saving your data
              Data storage

              1 Reply Last reply
              1
              • M Offline
                M Offline
                monster
                wrote on last edited by
                #9

                I'm afraid that it is too big amount of knowledge for such a small project, but I will consider it, thank you :)

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kornava
                  wrote on last edited by
                  #10

                  I think it can be much easier with LocalStorage , it can be done entirely from QML:
                  http://qmlbook.github.io/en/ch12/index.html#local-storage-sql

                  I think this is the simpler solution to establish saving ability for an app, but you can't access the stored information from outside your app.

                  1 Reply Last reply
                  0
                  • M monster

                    Thank you a LOT! Especially for Standard Paths. It works :) I've got last small question. I've noticed that I understand file operation modes wrong. Writing in append mode seems easy. As a ReadOnly mode, I understand the mode in which you start reading the file from the beggining. But now I found that WriteOnly mode erases all file and starts writing from the beginning! Is that right? I thought that WriteOnly opens the file with pointer pointing the beginning of file, and so I thought that writing in that mode allows me to replace previously written characters. I want to find the mode that allows me to change the number at the beginning without writing whole file again...

                    jsulmJ Online
                    jsulmJ Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @monster Use

                    QIODevice::WriteOnly | QIODevice::Append
                    

                    Then the file should not be overwritten.

                    You can declare structures containing strings. The size of the struct does not depend on the size of stored strings, because internally QString stores the actual string on the heap and just points to it. On my machine sizeof(StrStruct) is 16 (StrStruct contains two QString members). So it is 2 * sizeof(void*).

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • M Offline
                      M Offline
                      monster
                      wrote on last edited by
                      #12

                      Thank you all. Everything works fine. I just corrected my old, first example. There were many problems. I can upload example that works, and correctly fills and reads file according to the picked scheme if anybody is interested.

                      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