SQL & SQLQueryModel
-
wrote on 13 Apr 2016, 15:09 last edited by
Hi,
i'm learning how to work with sql in qt. so I do this:sqlQueryTable->exec("BEGIN TRANSACTION", false); sqlQueryTable->query()->prepare("INSERT INTO Pictures VALUES(?,?,?,?)"); LoadProgress progress(0,0,this); progress.show(); QCoreApplication::processEvents(); QVariantList ids; QVariantList filePaths; QVariantList paths; QVariantList fileNames; for (int i=0; i<fileList.count(); ++i) { ids.append(i); paths.append(QFileInfo(fileList[i]).absolutePath()); filePaths.append(QFileInfo(fileList[i]).absoluteFilePath()); fileNames.append(QFileInfo(fileList[i]).fileName()); } sqlQueryTable->query()->addBindValue(ids); sqlQueryTable->query()->addBindValue(fileNames); sqlQueryTable->query()->addBindValue(filePaths); sqlQueryTable->query()->addBindValue(paths); sqlQueryTable->query()->execBatch(); sqlQueryTable->exec("COMMIT");
sqlQueryTable is a class I created to access easier to QSqlQueryModel and QSqlQuery. so when I do this and get the rowCount() of the model it shows 256 but when I set a QListView's model to this model and scroll down to the last row and the get the rowCount() of the model It shows 9267 (the correct number). how can I get the rowCount right without having to scroll the listView?
Thanks in advance -
-
wrote on 14 Apr 2016, 04:11 last edited by
Hi @SGaist
thanks for helping but I don't just want to get the size I also want to get the values of the QSQlRecords that are in the model but the rowCount() doesn't show the correct size and also when I try to get a record in a row out of the rowCount() range the program crashe.
what should I do? -
Hi @SGaist
thanks for helping but I don't just want to get the size I also want to get the values of the QSQlRecords that are in the model but the rowCount() doesn't show the correct size and also when I try to get a record in a row out of the rowCount() range the program crashe.
what should I do?wrote on 14 Apr 2016, 05:15 last edited by@shahriar25
it's quite detail described in wiki."If the database supports returning the size of a query (see QSqlDriver::hasFeature()), the number of rows of the current query is returned. Otherwise, returns the number of rows currently cached on the client"
Obviously that your database doesn't support returning the size of a query.
QSqlQueryModel::fetchMore will help you ;)
-
wrote on 14 Apr 2016, 06:27 last edited by
Hi @slip
thanks I did't see that whole cached thing. thank you the problem is solved
1/5