QSqlQuery::value: not positioned on a valid record
-
wrote on 28 Dec 2013, 11:28 last edited by
After setting up a table model like this:
code is "here":http://stackoverflow.com/questions/20813955/qsqlqueryvalue-not-positioned-on-a-valid-recordthe content is displayed properly, but when I edit the data item then press enter ,this error occurred (more accurately, it is a warning rather than an error ,because the application doesn't crash when it happened .):
@
QSqlQuery::value: not positioned on a valid record
@when I close the application and restart it again ,I found the editing I did last time is not stored into the database ,anyone can fix my problem here .
Note:I did not use
@
model->removeColumn(0)
@here.
-
wrote on 28 Dec 2013, 17:46 last edited by
You already have been answered on the stackoverflow.com thread.
-
wrote on 29 Dec 2013, 02:49 last edited by
yes ,but that perhaps is not the right answer .
[quote author="Seba" date="1388252761"]You already have been answered on the stackoverflow.com thread.[/quote] -
Laszlo's answers are good
-
wrote on 31 Dec 2013, 01:11 last edited by
when I move model.setTable("names" ) and model.select() after the model.setRelation(0, QSqlRelation( "salaries", "id", "annual" ) ), just like this
http://codepad.org/zqri28oj ,
the problem disappeared . I don't understand why ,can you explain it ?
[quote author="SGaist" date="1388351689"]Laszlo's answers are good[/quote] -
If I'm not mistaken, you need only to move select after setRelation.
The call to select populates the model data, if you set the relation after, you're too late retrieve the data concerning the relation.
1/6