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. Qtsql table with correct number of rows but with no data
Forum Updated to NodeBB v4.3 + New Features

Qtsql table with correct number of rows but with no data

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.4k Views 2 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.
  • S Offline
    S Offline
    ShenDingDing
    wrote on last edited by
    #1

    I want to select some data from mysql using Qtsqlquerymodel, but the result table is empty, there is no data in it, but the number of rows is correct!0_1529163022191_捕获.PNG .0_1529163030342_捕获1.PNG

    KillerSmathK 1 Reply Last reply
    0
    • S ShenDingDing

      I want to select some data from mysql using Qtsqlquerymodel, but the result table is empty, there is no data in it, but the number of rows is correct!0_1529163022191_捕获.PNG .0_1529163030342_捕获1.PNG

      KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by KillerSmath
      #2

      @ShenDingDing
      Evertying is working well here.
      Have you checked if the query is returning rows with empty data, maybe because of encode character ?

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

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

        Hi and welcome to devnet,

        You should check what QSqlQueryModel::lastError returns.

        By the way, you can simplify your code by passing your query string directly to setQuery.

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

        S 1 Reply Last reply
        1
        • KillerSmathK KillerSmath

          @ShenDingDing
          Evertying is working well here.
          Have you checked if the query is returning rows with empty data, maybe because of encode character ?

          S Offline
          S Offline
          ShenDingDing
          wrote on last edited by
          #4

          @KillerSmath I have tied to select the data by QsqlQeury and output the value in a listview, and it works, so I think the problem is related to QsqlQueryModel

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi and welcome to devnet,

            You should check what QSqlQueryModel::lastError returns.

            By the way, you can simplify your code by passing your query string directly to setQuery.

            S Offline
            S Offline
            ShenDingDing
            wrote on last edited by
            #5

            @SGaist I tried and no error return, I also tried to check the data returned and it is not empty,0_1529193286124_7ceeb04b-c66d-4b68-b9b2-c231a9bebf97-image.png 0_1529193326512_afc25841-11e2-4ae4-8bf1-bb523c9dfdcf-image.png

            1 Reply Last reply
            0
            • S Offline
              S Offline
              ShenDingDing
              wrote on last edited by
              #6

              WOW I have solved it, I closes the database after I show the table and now I delete the "db.close()" and it shows data!!! But WHY???

              mrjjM 1 Reply Last reply
              0
              • S ShenDingDing

                WOW I have solved it, I closes the database after I show the table and now I delete the "db.close()" and it shows data!!! But WHY???

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @ShenDingDing
                hi
                Well the QsqlQueryModel is direct model to the database so if you close it
                it most likely detect that and cleans its internal structure since data no longer is available.
                Since you can change its Query at any time, it requires access to the db to fetch new data
                and it cannot open the db itself.

                S 1 Reply Last reply
                2
                • mrjjM mrjj

                  @ShenDingDing
                  hi
                  Well the QsqlQueryModel is direct model to the database so if you close it
                  it most likely detect that and cleans its internal structure since data no longer is available.
                  Since you can change its Query at any time, it requires access to the db to fetch new data
                  and it cannot open the db itself.

                  S Offline
                  S Offline
                  ShenDingDing
                  wrote on last edited by
                  #8

                  @mrjj Thank you~

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved