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. Select data from QSqlite in thread
Forum Updated to NodeBB v4.3 + New Features

Select data from QSqlite in thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 652 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.
  • I Offline
    I Offline
    isan
    wrote on last edited by isan
    #1

    I have used the thread to read data from QSqlite database

    void RandomWalk::run()
    {
        qDebug("Thread id inside run %d", (int)QThread::currentThreadId());
    
        QSqlQuery  qry(db);
        qry.prepare( "SELECT * FROM  TEST  ");
          if( !qry.exec() )
            qDebug() <<"here"<< qry.lastError();
          else
          {
            qDebug( "Selected!" );
    
            QSqlRecord rec = qry.record();
           
    
           for( int r=0; qry.next(); r++ ){
              qDebug() << QString( "Row %1, %2: %3" ).arg( r ).arg( rec.fieldName(0) ).arg( qry.value(0).toString() );
    
                qDebug() << QString( "Row %1, %2: %3" ).arg( r ).arg( rec.fieldName(1) ).arg( qry.value(1).toString() );
    
              }
          }
    }
    

    I don't use sleep in thread and it starts with : thread->start();
    the output like :

    "Row 0, Field1: 77"
    "Row 0, Field2: 87"
    "Row 1, Field1: 77"
    "Row 1, Field2: 87"
    "Row 2, Field1: 77"
    "Row 2, Field2: 87"
    "Row 3, Field1: 76"
    "Row 3, Field2: 86"
    "Row 4, Field1: 77"
    
    
    
    
    
    
    
    
    "Row 4, Field2: 87"
    "Row 5, Field1: 77"
    "Row 5, Field2: 87"
    "Row 6, Field1: 77"
    "Row 6, Field2: 87"
    "Row 7, Field1: 77"
    "Row 7, Field2: 87"
    
    
    
    
    
    
    ....
    

    Why is space between output data?Why is not read data continuous?

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

      Hi,

      What do you mean by space ?
      What is the expected output ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What do you mean by space ?
        What is the expected output ?

        I Offline
        I Offline
        isan
        wrote on last edited by isan
        #3

        @SGaist Hi , the space between Rows 4
        The output shouldn't continuous? like this:

        "Row 0, Field1: 77"
        "Row 0, Field2: 87"
        "Row 1, Field1: 77"
        "Row 1, Field2: 87"
        "Row 2, Field1: 77"
        "Row 2, Field2: 87"
        "Row 3, Field1: 76"
        "Row 3, Field2: 86"
        "Row 4, Field1: 77"
        "Row 4, Field2: 87"
        "Row 5, Field1: 77"
        "Row 5, Field2: 87"
        "Row 6, Field1: 77"
        "Row 6, Field2: 87"
        "Row 7, Field1: 77"
        "Row 7, Field2: 87"
        ....
        
        jsulmJ 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Each time you call qdebug, you get a new line printed on the console.

          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
          • I isan

            @SGaist Hi , the space between Rows 4
            The output shouldn't continuous? like this:

            "Row 0, Field1: 77"
            "Row 0, Field2: 87"
            "Row 1, Field1: 77"
            "Row 1, Field2: 87"
            "Row 2, Field1: 77"
            "Row 2, Field2: 87"
            "Row 3, Field1: 76"
            "Row 3, Field2: 86"
            "Row 4, Field1: 77"
            "Row 4, Field2: 87"
            "Row 5, Field1: 77"
            "Row 5, Field2: 87"
            "Row 6, Field1: 77"
            "Row 6, Field2: 87"
            "Row 7, Field1: 77"
            "Row 7, Field2: 87"
            ....
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #5

            @isan Maybe you have an entry in the database containing many newlines at the end?
            Use the debugger to see what data you get in each line.
            Also, these empty lines could be from another (main for example) thread.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • I isan

              I have used the thread to read data from QSqlite database

              void RandomWalk::run()
              {
                  qDebug("Thread id inside run %d", (int)QThread::currentThreadId());
              
                  QSqlQuery  qry(db);
                  qry.prepare( "SELECT * FROM  TEST  ");
                    if( !qry.exec() )
                      qDebug() <<"here"<< qry.lastError();
                    else
                    {
                      qDebug( "Selected!" );
              
                      QSqlRecord rec = qry.record();
                     
              
                     for( int r=0; qry.next(); r++ ){
                        qDebug() << QString( "Row %1, %2: %3" ).arg( r ).arg( rec.fieldName(0) ).arg( qry.value(0).toString() );
              
                          qDebug() << QString( "Row %1, %2: %3" ).arg( r ).arg( rec.fieldName(1) ).arg( qry.value(1).toString() );
              
                        }
                    }
              }
              

              I don't use sleep in thread and it starts with : thread->start();
              the output like :

              "Row 0, Field1: 77"
              "Row 0, Field2: 87"
              "Row 1, Field1: 77"
              "Row 1, Field2: 87"
              "Row 2, Field1: 77"
              "Row 2, Field2: 87"
              "Row 3, Field1: 76"
              "Row 3, Field2: 86"
              "Row 4, Field1: 77"
              
              
              
              
              
              
              
              
              "Row 4, Field2: 87"
              "Row 5, Field1: 77"
              "Row 5, Field2: 87"
              "Row 6, Field1: 77"
              "Row 6, Field2: 87"
              "Row 7, Field1: 77"
              "Row 7, Field2: 87"
              
              
              
              
              
              
              ....
              

              Why is space between output data?Why is not read data continuous?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @isan
              As the others say, you might have non-printing bytes in the column in the database. For your debug line try something like:

              qry.value(0).toString().toLatin1().toHex()
              

              in order to see what is actually in there.

              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