G'day all

having a problem getting text from a QTextEdit to
database field.
Doesn't seem to much database code around, no one Interesed???

suspect have to use QTextDocumunt but how.?????????

Qt Code:
  1. #include "dvd1.h"
  2. #include "ui_dvd1.h"
  3.  
  4. Dvd1::Dvd1(QWidget *parent)
  5. : QDialog(parent), ui(new Ui::Dvd1)
  6. {
  7. ui->setupUi(this);
  8.  
  9. if (QFile::exists("exdvd.sqlite")) {} // works ok
  10. else {
  11. setUpDb();
  12. }
  13.  
  14. connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(insertData()));
  15. }
  16.  
  17. Dvd1::~Dvd1()
  18. {
  19. delete ui;
  20. }
  21.  
  22. void Dvd1::setUpDb()
  23. {
  24. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  25. db.setDatabaseName("exdvd.sqlite");
  26. db.open();
  27.  
  28. QSqlQuery query = db.exec("CREATE TABLE IF NOT EXISTS table1"
  29. "(id integer primary key,"
  30. "title VARCHAR(60),"
  31. "library VARCHAR(15),"
  32. "number integer,"
  33. "notes VARCHAR(500))");
  34.  
  35. QSqlError err = db.lastError();
  36. if(!err.text().size() > 1)
  37. QMessageBox::information(0,"Error creating database", err.text());
  38.  
  39. }
  40.  
  41. void Dvd1::insertData()
  42. {
  43. QString str = "Hello There";
  44.  
  45. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  46. db.setDatabaseName("exdvd.sqlite");
  47. db.open();
  48.  
  49. // textDoc-> HOW TO GET textEdit TEXT TO textDoc???????????????????
  50.  
  51. // QSqlQuery query = db.exec("INSERT INTO 'table1' ('title', 'library', 'number', 'notes')" // works ok
  52. // " VALUES ('UnTame Bunch The', 'Wish List', '24', str);");
  53.  
  54. QSqlQuery query;
  55. query.prepare("INSERT INTO table1 (title, library, number, notes) " // works ok
  56. "VALUES (:title, :library, :number, :notes)");
  57. //query.bindValue(":title", "Chicken Little");
  58. query.bindValue(":title", ui->lineEdit->text()); //OK
  59. query.bindValue(":library", "Main");
  60. //query.bindValue(":number", 1010);
  61. query.bindValue(":number",ui->lineEdit_2->text()); //OK number field integer yet takes lineEdit.text???
  62. query.bindValue(":notes", str); // works ok
  63.  
  64. // query.bindValue(":notes", textDoc->WHAT?????????????HOW???????????
  65.  
  66.  
  67. if(!query.exec())
  68. {
  69. QSqlError err1=query.lastError(); // works checks query.prepare ONLY????
  70. QMessageBox::information(this,"Query Error",err1.text());
  71. }
  72. }
To copy to clipboard, switch view to plain text mode 

this creates table and inserts data ok
checked OK with Sqliteman

using Qt 4.5,2 kde4.3.2 QtCreator 1.2.1
QtCreator is the ants pants
regards
briang