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?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 479 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.
  • B Offline
    B Offline
    bogong
    wrote on 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?

    kshegunovK 1 Reply Last reply
    0
    • B bogong

      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?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on 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
      3
      • kshegunovK kshegunov

        @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 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?

        kshegunovK 1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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

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

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on 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 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