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. QSqlquery exec and prepare sometimes stuck
Forum Updated to NodeBB v4.3 + New Features

QSqlquery exec and prepare sometimes stuck

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 2 Posters 1.9k 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.
  • NickVN Offline
    NickVN Offline
    NickV
    wrote on last edited by
    #1

    Hello everyone.
    I'm facing the following problem:
    I have addDatabase in the constructor of my class. I run with qtconcurrent a function that opens the database. The database object is in a variable that called db. When i call another function that executes a query in the db the code stuck. I found that the problem is with exec or with the prepare. This is not happens all the time. Sometimes after a few calls of the same function the code stuck.
    Any suggestions?

    kshegunovK 1 Reply Last reply
    0
    • NickVN NickV

      Hello everyone.
      I'm facing the following problem:
      I have addDatabase in the constructor of my class. I run with qtconcurrent a function that opens the database. The database object is in a variable that called db. When i call another function that executes a query in the db the code stuck. I found that the problem is with exec or with the prepare. This is not happens all the time. Sometimes after a few calls of the same function the code stuck.
      Any suggestions?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @NickV said in QSqlquery exec and prepare sometimes stuck:

      I run with qtconcurrent a function that opens the database.

      How and why?

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • NickVN Offline
        NickVN Offline
        NickV
        wrote on last edited by NickV
        #3

        The code of establishing connection is:
        QFuture<void> future = QtConcurrent::run(this, &DatabaseManager::establish_connection);

        I'm using qtconcurrent because the connection stuck my interface untill database open and this is not very good for my application.

        kshegunovK 1 Reply Last reply
        0
        • NickVN NickV

          The code of establishing connection is:
          QFuture<void> future = QtConcurrent::run(this, &DatabaseManager::establish_connection);

          I'm using qtconcurrent because the connection stuck my interface untill database open and this is not very good for my application.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          What does DatabaseManager::establish_connection do? Also are you making sure you don't access the database before the job has finished?

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • NickVN Offline
            NickVN Offline
            NickV
            wrote on last edited by
            #5

            This function sets the hostname, username and password of the database and the opens it. Nothing more. The addDatabase is not in this function in order to be able to use the database instance from every part of my code.

            kshegunovK 1 Reply Last reply
            0
            • NickVN NickV

              This function sets the hostname, username and password of the database and the opens it. Nothing more. The addDatabase is not in this function in order to be able to use the database instance from every part of my code.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              I think you either have some strange race condition, or the connection to the database is dropped/busy so the prepare and/or exec are lagging.

              Read and abide by the 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