Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Custom component and SQL data
Forum Updated to NodeBB v4.3 + New Features

Custom component and SQL data

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 1.9k Views 3 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.
  • J Offline
    J Offline
    JasonS
    wrote on 23 Mar 2017, 18:16 last edited by
    #1

    I have a multi-tab QML form that loads a custom component with various controls such as TextEdit boxes, buttons, labels and want to load data from SQLite into the TextEdit boxes to provide update capabilities. I've found a couple things that seem like the would work, but I'm having a difficult time translating the examples into my application. I think the Books example is doing what I want to do, but this example is using a UI file, not a QML form (QML file) like I have and am getting caught up on making the connection between the two. The example I'm referring to is http://doc.qt.io/qt-5/qtsql-books-example.html

    Does anyone have any guidance to help me load data from SQLite and map it to UI objects in QML?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 23 Mar 2017, 19:41 last edited by
      #2

      Hi! You're lucky, there is already a component to access SQLite databases from QML, see Qt Quick Local Storage QML Types :-)

      1 Reply Last reply
      1
      • J Offline
        J Offline
        JasonS
        wrote on 23 Mar 2017, 19:56 last edited by
        #3

        That was my original solution, but I wasn't able to find a way to specify the path and name of the database file.

        https://forum.qt.io/topic/76166/location-of-sqlite-database/5

        Do you know of a way to set the path and file name?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on 23 Mar 2017, 20:19 last edited by
          #4

          Mhh, unfortunatly, setting the filename is not supported. I think (might be wrong) this is because LocalStorage is implemented as a plugin to QML's Javascript engine. The best way to use your SQLite file from QML is probably to write a backend in C++ that accesses the file and exposes one ListModel for each DB table to the QML side.

          1 Reply Last reply
          1
          • J Offline
            J Offline
            JasonS
            wrote on 23 Mar 2017, 21:09 last edited by
            #5

            So that's how I got down the path of the Books example. I have a C++ backend creating a QSqlRelationalTableModel and can load the data to a ListView easily by setting the model, but my controls are not in the LIstView format. I was attempting to use a role name of the QSqlRelationalTableModel and set the text of a TextEdit control, but kept running into Unable to assign [undefined] to QString. I found a similar issue that thought they weren't generating their role names correctly so when looking for a solution to that I ran into mapping SQL data to widgets. I was hoping for an easy way to map data to controls instead of writing a bunch of code.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 23 Mar 2017, 21:46 last edited by
              #6

              Hi,

              There's also this wiki entry that shows how to use a QSqlQueryModel with QML.

              IIRC there was a project aiming to provide a QML wrapper to Qt's SQL module but I can't find it currently.

              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
              • J Offline
                J Offline
                JasonS
                wrote on 24 Mar 2017, 18:05 last edited by
                #7

                Is this what you are thinking about by chance?

                https://github.com/JosephMillsAtWork/QmlSql

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 24 Mar 2017, 21:41 last edited by
                  #8

                  Might be yes

                  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

                  4/8

                  23 Mar 2017, 20:19

                  • Login

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