QTableview data disappear..
-
@TheCipo76 said in QTableview data disappear..:
mDatabase.close();
How should this work? A QSqlModel needs access to the database at any time...
-
@TheCipo76 said in QTableview data disappear..:
mDatabase.close();
How should this work? A QSqlModel needs access to the database at any time...
-
It works as long as the model does not need to refetch data from the database (e.g. due to scrolling or other circumstances).
-
It works as long as the model does not need to refetch data from the database (e.g. due to scrolling or other circumstances).
@Christian-Ehrlicher No, i'have tried to scroll and works fine.
This is only view of DB data.. no need to modify nothing in this dialog
and no need to reload data -
I'm giving up... would you please at least try to not to close the database and see if your problem goes away?
-
I'm giving up... would you please at least try to not to close the database and see if your problem goes away?
@Christian-Ehrlicher Yes, i have putted "//" before close database instruction
//mDatabase.close();
but warning still remain..
-
Are you calling
QSqlDatabase::addDatabase("QMYSQL");
in several places in your application ? -
Are you calling
QSqlDatabase::addDatabase("QMYSQL");
in several places in your application ?@SGaist Yes, in every dialog who need to connect to database..
but in every dialog call
ordforauto::~ordforauto() { if (aDatabase.open()) { aDatabase.close(); } QSqlDatabase::removeDatabase("QMYSQL"); delete ui; }
in the code or at least in the unload istructions as you see
-
http://doc.qt.io/qt-5/qsqlquery.html#details
Warning: You must load the SQL driver and open the connection before a QSqlQuery is created. Also, the connection must remain open while the query exists; otherwise, the behavior of QSqlQuery is undefined.
-
Why are you doing it like that ? There's no need to nuke and recreate the connection each time.
If you really want to do it like that, then you should create a connection with a different name in each of your dialog.
Because currently, you are manipulating the default connection from several places in a wrong manner.
-
Why are you doing it like that ? There's no need to nuke and recreate the connection each time.
If you really want to do it like that, then you should create a connection with a different name in each of your dialog.
Because currently, you are manipulating the default connection from several places in a wrong manner.
-
http://doc.qt.io/qt-5/qsqlquery.html#details
Warning: You must load the SQL driver and open the connection before a QSqlQuery is created. Also, the connection must remain open while the query exists; otherwise, the behavior of QSqlQuery is undefined.
@Christian-Ehrlicher i will check all dialogs.. but i think that is what i've done..
-
@Christian-Ehrlicher i will check all dialogs.. but i think that is what i've done..
@TheCipo76 As shown here: http://doc.qt.io/qt-5/qsqldatabase.html
Create and open db connection:QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL"); db.setHostName("acidalia"); db.setDatabaseName("customdb"); db.setUserName("mojito"); db.setPassword("J0a1m8"); bool ok = db.open();
When you need the connection just get it:
QSqlDatabase db = QSqlDatabase::database();
No need to open and close it all the time.
-
@TheCipo76 As shown here: http://doc.qt.io/qt-5/qsqldatabase.html
Create and open db connection:QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL"); db.setHostName("acidalia"); db.setDatabaseName("customdb"); db.setUserName("mojito"); db.setPassword("J0a1m8"); bool ok = db.open();
When you need the connection just get it:
QSqlDatabase db = QSqlDatabase::database();
No need to open and close it all the time.