Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Correct way to use QSqlQueryModel in the different thread. How?
Forum Updated to NodeBB v4.3 + New Features

Correct way to use QSqlQueryModel in the different thread. How?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 496 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.
  • B Offline
    B Offline
    bogong
    wrote on 25 Jul 2021, 08:44 last edited by
    #1

    Hello all!
    How to use QSqlQueryModel in the different thread correctly?
    I have DB that is in different thread (worker schema/service schema) and it's working perfectly when I am using with QSqlQuery. How to implement the QSqlQueryModel that is preforming all DB requests in another thread?

    K 1 Reply Last reply 25 Jul 2021, 10:07
    0
    • B bogong
      25 Jul 2021, 08:44

      Hello all!
      How to use QSqlQueryModel in the different thread correctly?
      I have DB that is in different thread (worker schema/service schema) and it's working perfectly when I am using with QSqlQuery. How to implement the QSqlQueryModel that is preforming all DB requests in another thread?

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 25 Jul 2021, 10:07 last edited by
      #2

      @bogong said in Correct way to use QSqlQueryModel in the different thread. How?:

      How to use QSqlQueryModel in the different thread correctly?

      You can't.

      Read and abide by the Qt Code of Conduct

      B 1 Reply Last reply 25 Jul 2021, 15:06
      3
      • K kshegunov
        25 Jul 2021, 10:07

        @bogong said in Correct way to use QSqlQueryModel in the different thread. How?:

        How to use QSqlQueryModel in the different thread correctly?

        You can't.

        B Offline
        B Offline
        bogong
        wrote on 25 Jul 2021, 15:06 last edited by
        #3

        @kshegunov Do you know the reason of it? Is there something special of why it not possible? Or it's just not developed?

        K 1 Reply Last reply 25 Jul 2021, 18:19
        0
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 25 Jul 2021, 15:45 last edited by
          #4

          The reason is that you can't modify gui elements from another thread than the main thread.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2
          • B bogong
            25 Jul 2021, 15:06

            @kshegunov Do you know the reason of it? Is there something special of why it not possible? Or it's just not developed?

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 25 Jul 2021, 18:19 last edited by
            #5

            What @Christian-Ehrlicher wrote, but more specifically, to have a query in a thread the QSqlQuery object must be created and accessed only from that thread, and even then the model can't be moved to worker, because the views (which are GUI objects) are not designed to handle it.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            3
            • B Offline
              B Offline
              bogong
              wrote on 24 Aug 2021, 15:48 last edited by bogong
              #6

              Solution found. Might be not so elegant but it works for me. Example published. The video of how it works for mobile here. It's not from model directly, but all of procedures with DB is in different thread.

              Thx to all.
              Issue closed.

              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