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. loading data from database using another thread
Qt 6.11 is out! See what's new in the release blog

loading data from database using another thread

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 3 Posters 5.8k 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.
  • KroMignonK KroMignon

    @Christian-Ehrlicher said in loading data from database using another thread:

    you must not move access a QSqlDatabase from a different thread!

    Yes I know, but this is only the result of the request, there are no SQL statement which will be handled. Only the result of the old request.
    What's wrong with this?

    P Offline
    P Offline
    Proton Phoenix
    wrote on last edited by
    #12

    @KroMignon
    hi bro again
    is there any solution
    with const lambda

    while(qry.next()){  // error here
                      counters +=qry.value(colCounter).toFloat();
                  }
    

    it says this error !
    'this' argument to member function 'next' has type 'const QSqlQuery', but function is not marked const
    qsqlquery.h:92:10: note: 'next' declared here

    KroMignonK 1 Reply Last reply
    0
    • P Proton Phoenix

      @KroMignon
      hi bro again
      is there any solution
      with const lambda

      while(qry.next()){  // error here
                        counters +=qry.value(colCounter).toFloat();
                    }
      

      it says this error !
      'this' argument to member function 'next' has type 'const QSqlQuery', but function is not marked const
      qsqlquery.h:92:10: note: 'next' declared here

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #13

      @Proton-Phoenix said in loading data from database using another thread:

      is there any solution
      with const lambda

      No, you cannot use QSqlQuery::next(), with a const instance.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Proton Phoenix
        wrote on last edited by Proton Phoenix
        #14

        thank you bro
        when i add mutable problem Disappeared .. and it loads data from another thread successfully Finally :D

        Really Thank you guys

        QFuture<float> future = QtConcurrent::run([qry]()mutable ->float {
        
        
        1 Reply Last reply
        0
        • KroMignonK KroMignon

          @Christian-Ehrlicher said in loading data from database using another thread:

          you must not move access a QSqlDatabase from a different thread!

          Yes I know, but this is only the result of the request, there are no SQL statement which will be handled. Only the result of the old request.
          What's wrong with this?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #15

          @KroMignon said in loading data from database using another thread:

          Yes I know, but this is only the result of the request, there are no SQL statement which will be handled. Only the result of the old request.
          What's wrong with this?

          QSqlQuery does not have the data, it only fetches the data when you call e.g. next() so it still uses the database connection.

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

          KroMignonK 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            @KroMignon said in loading data from database using another thread:

            Yes I know, but this is only the result of the request, there are no SQL statement which will be handled. Only the result of the old request.
            What's wrong with this?

            QSqlQuery does not have the data, it only fetches the data when you call e.g. next() so it still uses the database connection.

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #16

            @Christian-Ehrlicher said in loading data from database using another thread:

            QSqlQuery does not have the data, it only fetches the data when you call e.g. next() so it still uses the database connection.

            Indeed, that's sound bad :(
            I misunderstood how QSqlQuery works, I believe it launch the request and store the result locally.

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #17

              @KroMignon said in loading data from database using another thread:

              I believe it launch the request and store the result locally.

              This would be a very bad behavior for large result sets.

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

              KroMignonK 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                @KroMignon said in loading data from database using another thread:

                I believe it launch the request and store the result locally.

                This would be a very bad behavior for large result sets.

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #18

                @Christian-Ehrlicher said in loading data from database using another thread:

                This would be a very bad behavior for large result sets.

                You are right.
                This will made this a little bit more complex, because the SQL connection have to leave in another thread, which means a new DB connection is required.

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                Christian EhrlicherC 1 Reply Last reply
                0
                • KroMignonK KroMignon

                  @Christian-Ehrlicher said in loading data from database using another thread:

                  This would be a very bad behavior for large result sets.

                  You are right.
                  This will made this a little bit more complex, because the SQL connection have to leave in another thread, which means a new DB connection is required.

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #19

                  @KroMignon Or do only the calculation in the other thread.

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

                  P 2 Replies Last reply
                  1
                  • Christian EhrlicherC Christian Ehrlicher

                    @KroMignon Or do only the calculation in the other thread.

                    P Offline
                    P Offline
                    Proton Phoenix
                    wrote on last edited by Proton Phoenix
                    #20

                    @Christian-Ehrlicher
                    do i need to change anything???

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @KroMignon Or do only the calculation in the other thread.

                      P Offline
                      P Offline
                      Proton Phoenix
                      wrote on last edited by Proton Phoenix
                      #21

                      @Christian-Ehrlicher and @KroMignon
                      i did it successfully Thanks you so much your opinions helped me to fix the Big O problem too
                      now it's only calculation with the other thread
                      <3

                      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