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. Qt Mobile Application for Android
Forum Updated to NodeBB v4.3 + New Features

Qt Mobile Application for Android

Scheduled Pinned Locked Moved Solved Mobile and Embedded
18 Posts 4 Posters 2.9k Views 4 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    In memory database is not what you since as soon as your application stops, the database is destroyed.

    The most classical way would be to create the database in the correct location using QStandardPaths using DataLocation. If the database is empty by default then you can simply create it if doesn't exist at the start of your application.

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

    D 1 Reply Last reply
    2
    • SGaistS SGaist

      Hi and welcome to devnet,

      In memory database is not what you since as soon as your application stops, the database is destroyed.

      The most classical way would be to create the database in the correct location using QStandardPaths using DataLocation. If the database is empty by default then you can simply create it if doesn't exist at the start of your application.

      D Offline
      D Offline
      divaindie
      wrote on last edited by divaindie
      #3

      @SGaist actually in my case I need to attach a database file which has defualt values loaded into it along with my application . I think this purpose can serve better with in-memory database.from the below link I got the idea of in-memory but I don't know how I can create an in-memory db and dump it to a qrc file .
      https://stackoverflow.com/questions/4254250/embedded-database-in-qt

      Or please tell me any other ways through which I can provide database file along with my application.
      FYI my application is an android app.

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

        The most simple is to just create the database in file as normal and then copy that file into your project folder.

        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
        • D Offline
          D Offline
          divaindie
          wrote on last edited by
          #5

          Understood .that I had tried already .then how I can attach this file in qrc ?

          ekkescornerE 1 Reply Last reply
          0
          • D divaindie

            Understood .that I had tried already .then how I can attach this file in qrc ?

            ekkescornerE Online
            ekkescornerE Online
            ekkescorner
            Qt Champions 2016
            wrote on last edited by
            #6

            @divaindie simply add the file to a .qrc
            I'm providing per ex a JSON settings file this way:

            <RCC>
                <qresource prefix="/">
                    <file>data-assets/cacheSettingsData.json</file>
                </qresource>
            </RCC>
            

            then in my app I'm checking if the file already exists in my appdata - if not I copy it

            ekke ... Qt Champion 2016 | 2024 ... mobile business apps
            5.15 --> 6.9 https://t1p.de/ekkeChecklist
            QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

            D 1 Reply Last reply
            0
            • ekkescornerE ekkescorner

              @divaindie simply add the file to a .qrc
              I'm providing per ex a JSON settings file this way:

              <RCC>
                  <qresource prefix="/">
                      <file>data-assets/cacheSettingsData.json</file>
                  </qresource>
              </RCC>
              

              then in my app I'm checking if the file already exists in my appdata - if not I copy it

              D Offline
              D Offline
              divaindie
              wrote on last edited by divaindie
              #7

              @ekkescorner I don't know about JSON file .but adding a database file in qrc doesn't work .you can see this link https://stackoverflow.com/questions/4254250/embedded-database-in-qt

              D 1 Reply Last reply
              0
              • D divaindie

                @ekkescorner I don't know about JSON file .but adding a database file in qrc doesn't work .you can see this link https://stackoverflow.com/questions/4254250/embedded-database-in-qt

                D Offline
                D Offline
                divaindie
                wrote on last edited by divaindie
                #8

                @divaindie basically we can add only binary files into qrc. during compilation of Qt application ,qmake will create a file called qrc_application.cpp file from .qrc file .
                .this qrc_application.cpp will have pointers to binary dump of resources which are added into .qrc file before building .This link will explain more about qrc system in Qt http://doc.qt.io/qt-5/resources.html
                suppose if we include a database file(which is not a binary file) into .qrc ,it will not work because "The database name is just the path to the file. Qt does not intercept the file name but hands it over directly to the SQLite functions (by calling toUtf8() on the “path”), which in turn try to open that file – and will eventually fail, of course."
                You can find this in below qt forum thread
                https://forum.qt.io/topic/3949/sqlite-database-in-project/3

                This is the reason why I found in-memory database is the solution to my problem .If you see this link you will get why I had choosen in-memory database
                https://stackoverflow.com/questions/4254250/embedded-database-in-qt
                But I don't know how to do it .If you have the solution /or any alternative solution let me know

                ekkescornerE 1 Reply Last reply
                0
                • D divaindie

                  @divaindie basically we can add only binary files into qrc. during compilation of Qt application ,qmake will create a file called qrc_application.cpp file from .qrc file .
                  .this qrc_application.cpp will have pointers to binary dump of resources which are added into .qrc file before building .This link will explain more about qrc system in Qt http://doc.qt.io/qt-5/resources.html
                  suppose if we include a database file(which is not a binary file) into .qrc ,it will not work because "The database name is just the path to the file. Qt does not intercept the file name but hands it over directly to the SQLite functions (by calling toUtf8() on the “path”), which in turn try to open that file – and will eventually fail, of course."
                  You can find this in below qt forum thread
                  https://forum.qt.io/topic/3949/sqlite-database-in-project/3

                  This is the reason why I found in-memory database is the solution to my problem .If you see this link you will get why I had choosen in-memory database
                  https://stackoverflow.com/questions/4254250/embedded-database-in-qt
                  But I don't know how to do it .If you have the solution /or any alternative solution let me know

                  ekkescornerE Online
                  ekkescornerE Online
                  ekkescorner
                  Qt Champions 2016
                  wrote on last edited by ekkescorner
                  #9

                  @divaindie have you tried it this way ? https://stackoverflow.com/a/40713888/135559

                  or this: https://forum.qt.io/topic/94088/deploy-sqlite-database-with-apk/12

                  ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                  5.15 --> 6.9 https://t1p.de/ekkeChecklist
                  QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                  D 1 Reply Last reply
                  0
                  • ekkescornerE ekkescorner

                    @divaindie have you tried it this way ? https://stackoverflow.com/a/40713888/135559

                    or this: https://forum.qt.io/topic/94088/deploy-sqlite-database-with-apk/12

                    D Offline
                    D Offline
                    divaindie
                    wrote on last edited by divaindie
                    #10

                    @ekkescorner i tried the link https://forum.qt.io/topic/94088/deploy-sqlite-database-with-apk/12

                    but i got below error message while copying db file to a writable location ( i.e QStandardPaths::writableLocation(QStandardPaths::StandardLocation::AppDataLocation); )

                    W QtMainThread: type=1400 audit(0.0:119): avc: denied { link } for name="qt_temp.xajbeT" dev="dm-0" ino=124288 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=file permissive=0

                    edit1 : it works if i use "QStandardPaths::GenericDataLocation" instead of "QStandardPaths::StandardLocation::AppDataLocation".
                    now my question is which location i should prefer using to copy my database file from assets:/ folder ? .(FYI both read/write opearion allowed on database file)

                    ekkescornerE 1 Reply Last reply
                    0
                    • D divaindie

                      @ekkescorner i tried the link https://forum.qt.io/topic/94088/deploy-sqlite-database-with-apk/12

                      but i got below error message while copying db file to a writable location ( i.e QStandardPaths::writableLocation(QStandardPaths::StandardLocation::AppDataLocation); )

                      W QtMainThread: type=1400 audit(0.0:119): avc: denied { link } for name="qt_temp.xajbeT" dev="dm-0" ino=124288 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=file permissive=0

                      edit1 : it works if i use "QStandardPaths::GenericDataLocation" instead of "QStandardPaths::StandardLocation::AppDataLocation".
                      now my question is which location i should prefer using to copy my database file from assets:/ folder ? .(FYI both read/write opearion allowed on database file)

                      ekkescornerE Online
                      ekkescornerE Online
                      ekkescorner
                      Qt Champions 2016
                      wrote on last edited by
                      #11

                      @divaindie what's your Qt version ?
                      there were issues with temp files causing errors while copying on Android
                      5.10.1 and 5.11.1 should be ok

                      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                      5.15 --> 6.9 https://t1p.de/ekkeChecklist
                      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                      D 1 Reply Last reply
                      0
                      • ekkescornerE ekkescorner

                        @divaindie what's your Qt version ?
                        there were issues with temp files causing errors while copying on Android
                        5.10.1 and 5.11.1 should be ok

                        D Offline
                        D Offline
                        divaindie
                        wrote on last edited by
                        #12

                        @ekkescorner iam using 5.10.1 !!! .which version of Qt works fine for developing Android applications?

                        ekkescornerE 1 Reply Last reply
                        0
                        • D divaindie

                          @ekkescorner iam using 5.10.1 !!! .which version of Qt works fine for developing Android applications?

                          ekkescornerE Online
                          ekkescornerE Online
                          ekkescorner
                          Qt Champions 2016
                          wrote on last edited by
                          #13

                          @divaindie 5.10.1 should be fine.
                          can you create, save and copy a normal text file at your AppDataLocation ?

                          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                          5.15 --> 6.9 https://t1p.de/ekkeChecklist
                          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            divaindie
                            wrote on last edited by divaindie
                            #14

                            @ekkescorner Iam able to create files.but i cant read/write/copy files to AppDataLocation

                            ekkescornerE 1 Reply Last reply
                            0
                            • D divaindie

                              @ekkescorner Iam able to create files.but i cant read/write/copy files to AppDataLocation

                              ekkescornerE Online
                              ekkescornerE Online
                              ekkescorner
                              Qt Champions 2016
                              wrote on last edited by
                              #15

                              @divaindie curios.
                              I'm using this to get the appdata location

                              mDataRoot = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
                              

                              then I'm checking if the directory exists, but this should exists on Android, but must be created on iOS
                              to be safe I'm always checking

                              QDir myDir;
                                  bool exists;
                                  exists = myDir.exists(mDataRoot);
                                  if (!exists) {
                                      bool ok = myDir.mkpath(mDataRoot);
                                      if(!ok) {
                                          qWarning() << "Couldn't create mDataRoot " << mDataRoot;
                                          return false;
                                      }
                                      qDebug() << "created directory mDataRoot " << mDataRoot;
                                  }
                              

                              then as next I'm creating a /data/ directory and place all my other files ond folders inside this
                              never had problems with read write delete copy

                              ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                              5.15 --> 6.9 https://t1p.de/ekkeChecklist
                              QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                              D 1 Reply Last reply
                              1
                              • ekkescornerE ekkescorner

                                @divaindie curios.
                                I'm using this to get the appdata location

                                mDataRoot = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
                                

                                then I'm checking if the directory exists, but this should exists on Android, but must be created on iOS
                                to be safe I'm always checking

                                QDir myDir;
                                    bool exists;
                                    exists = myDir.exists(mDataRoot);
                                    if (!exists) {
                                        bool ok = myDir.mkpath(mDataRoot);
                                        if(!ok) {
                                            qWarning() << "Couldn't create mDataRoot " << mDataRoot;
                                            return false;
                                        }
                                        qDebug() << "created directory mDataRoot " << mDataRoot;
                                    }
                                

                                then as next I'm creating a /data/ directory and place all my other files ond folders inside this
                                never had problems with read write delete copy

                                D Offline
                                D Offline
                                divaindie
                                wrote on last edited by divaindie
                                #16

                                @ekkescorner this worked for me.thanks!!.
                                for linux & windows if i want to add my database file what changes i need to make in .pro file ?.
                                for android i made below changes.
                                android
                                {
                                my_files.path = /assets
                                my_files.files = $$PWD/android/*
                                INSTALLS += my_files
                                }

                                ekkescornerE Pablo J. RoginaP 2 Replies Last reply
                                0
                                • D divaindie

                                  @ekkescorner this worked for me.thanks!!.
                                  for linux & windows if i want to add my database file what changes i need to make in .pro file ?.
                                  for android i made below changes.
                                  android
                                  {
                                  my_files.path = /assets
                                  my_files.files = $$PWD/android/*
                                  INSTALLS += my_files
                                  }

                                  ekkescornerE Online
                                  ekkescornerE Online
                                  ekkescorner
                                  Qt Champions 2016
                                  wrote on last edited by ekkescorner
                                  #17

                                  @divaindie good to hear that it's working for you

                                  ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                                  5.15 --> 6.9 https://t1p.de/ekkeChecklist
                                  QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                                  1 Reply Last reply
                                  0
                                  • D divaindie

                                    @ekkescorner this worked for me.thanks!!.
                                    for linux & windows if i want to add my database file what changes i need to make in .pro file ?.
                                    for android i made below changes.
                                    android
                                    {
                                    my_files.path = /assets
                                    my_files.files = $$PWD/android/*
                                    INSTALLS += my_files
                                    }

                                    Pablo J. RoginaP Offline
                                    Pablo J. RoginaP Offline
                                    Pablo J. Rogina
                                    wrote on last edited by
                                    #18

                                    @divaindie said in Qt Mobile Application for Android:

                                    for linux & windows if i want to add my database file what changes i need to make in .pro file ?

                                    Maybe it'd be good you mark this post as solved since you originally asked for Android and it's working for you now, and open a new post for the other platforms so not to hijack the post. Thanks.

                                    Upvote the answer(s) that helped you solve the issue
                                    Use "Topic Tools" button to mark your post as Solved
                                    Add screenshots via postimage.org
                                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                                    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