PDA

View Full Version : Insert values into database table



l0ner
20th June 2011, 13:31
I have two classes: one is my MainWindow in which I create connection to database, other one is a QDialog from which I want insert new rows into the database table.
QDialog is called form inside of MainWindow (through menu).
Problem is the QDialog don't seems to see the database connection created by MainWindow.
How can I make the db wisible to QDialog?

you can view my code here: http://code.google.com/p/neurohelper/source/browse/#svn%2Ftrunk
MainWindow: http://code.google.com/p/neurohelper/source/browse/trunk/mainwindow.cpp
QDialog: http://code.google.com/p/neurohelper/source/browse/trunk/adduserdialog.cpp

Any help?

pkj
20th June 2011, 16:01
Could you qDebug()<<query.lastError() after the insert and provide the output?

l0ner
20th June 2011, 18:29
I did it myself and discovered that problem lied within query. Shame on me.
But now I have similiar problem. My central widget inside main window contains other widgets. How many widgets are added to central widget depends on how many rows I have in primary table inside my database. Problem is that when i try to execute query from within my central widget query.exec() returns false. lastError() from query is:

QSqlError(-1, "Unable to fetch row", "No query")

You can look at code of my central widget here: http://code.google.com/p/neurohelper/source/browse/trunk/playergrid.cpp

Connection to database is created by Main Window.

Edit: and again problem lied somewhere within the query.

DanH
20th June 2011, 20:03
http://doc.qt.nokia.com/4.7/sql-connecting.html