Unsolved Qtsql table with correct number of rows but with no data
-
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! .
-
@ShenDingDing
Evertying is working well here.
Have you checked if the query is returning rows with empty data, maybe because of encode character ? -
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.
-
@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
-
@SGaist I tried and no error return, I also tried to check the data returned and it is not empty,
-
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???
-
@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. -
@mrjj Thank you~