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. Is QSqlQueryModel an alternative to QSqlQuery? - Qt
Forum Updated to NodeBB v4.3 + New Features

Is QSqlQueryModel an alternative to QSqlQuery? - Qt

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 2 Posters 2.6k Views 1 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.
  • R Offline
    R Offline
    raj.qtdev
    wrote on last edited by
    #1

    Hi,

    I am using QSqlQuery in my Qt application. During the application run, i sometimes get error which says "Unable to fetch row. Database locked.".

    I found somebody suggesting QSqlQueryModel as an alternate to QSqlQuery. Is it so because the documentation says that QSqlQueryModel provides a read only data model for sql results sets which means this can be used only to retrieve data from the database. On the other hand QSqlQuery can be used to execute all kinds of sql queries.

    What do you have to say on this.

    Thanks

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

      Hi,

      What kind of database are you accessing ? Are you accessing it alone ?

      QSqlQueryModel vs QSqlQuery is more a question of what you are doing in 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

      1 Reply Last reply
      0
      • R Offline
        R Offline
        raj.qtdev
        wrote on last edited by
        #3

        Sorry forgot to mention that. Its a sqlite database. I am using QSqlDatabase API for this. In the application I would use most of the database operations like create, add, delete, update.

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

          Are you using multi threading in your application ?

          You can also have a look at QSqlTableModel for this kind of activity

          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
          • R Offline
            R Offline
            raj.qtdev
            wrote on last edited by
            #5

            Yes I am using multithreading in the app. So are you suspecting that "unable to fetch row" error is related to accessing the database from two different threads is it?

            But this scenario might happen even if I use QSqlTableModel. So does that mean that there is something wrong in the way I am using multithreading in my application is it? Because I have also observed that my application hangs frequently and whenever it hangs, there is some DB call going on the in background which keeps returning "unable to fetch row".

            Please suggest what is the better way to do it.

            Thanks

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

              Then I guess that you are using sqlite for your database ? "this":http://qt-project.org/forums/viewthread/23702 might help you

              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

              • Login

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