Hi,

I was following a tutorial to learn something about Qt and C++ but at one point my code does not work. I try to enter some data in a fresh created SQLite3 database. The database was create with the FireFox add-on and is empty at the moment. I double checked that all names are correct and watched the tutorial three time to figure out what I did wrong.
Here is the code for inserting. I am quite sure that I am connected to the data base be cause I can read from a different table.
Qt Code:
  1. Settings::Settings(QWidget *parent) :
  2. QDialog(parent),
  3. ui(new Ui::Settings)
  4. {
  5. ui->setupUi(this);
  6. MainWindow connect;
  7. if(connect.conOpen()){
  8. qDebug()<<("Connected...");
  9. }else{
  10. qDebug()<<("Not connected!");
  11. }
  12. }
  13.  
  14. void Settings::on_pushButton_ok_clicked(){
  15. // Save data to db
  16. MainWindow connect; // here are the functions conOpen() and conClose() defined
  17. QString str1, str2;
  18. QDateTime date(QDateTime::currentDateTime());
  19.  
  20. str1=ui->editName->text();
  21. str2=ui->editPassword->text();
  22.  
  23. QSqlQuery qry;
  24. qry.prepare("insert into table (name,password,date) values ('"+str1+"', "+str2+", "+date.toString()+")");
  25. if(qry.exec()){
  26. qDebug()<<("Data was saved");
  27. // Sent result to log on MainWindow
  28. connect.conClose();
  29. this->hide();
  30. }else{
  31. qDebug()<<(qry.lastError().text());
  32. }
  33. }
To copy to clipboard, switch view to plain text mode 
Before I try to write to the data base I closed the old connection and opened a new one. Here is the output:
Qt Code:
  1. Connected to database...
  2. Connected...
  3. QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
  4. Connected to database...
  5. " Parameter count mismatch"
To copy to clipboard, switch view to plain text mode 
I have read that there are issues if you create a SQLite DB with Qt but I did not. Does anyone see what I did wrong?