Results 1 to 3 of 3

Thread: Simple DataBase problems

  1. #1
    Join Date
    Oct 2009
    Location
    tathra nsw australia
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    8

    Question Simple DataBase problems

    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

  2. #2
    Join Date
    Jul 2009
    Posts
    139
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    13
    Thanked 59 Times in 52 Posts

    Default Re: Simple DataBase problems

    Are you looking for QTextEdit::toPlainText? Or QTextEdit::toHtml?

  3. The following user says thank you to numbat for this useful post:

    briang (1st January 2010)

  4. #3
    Join Date
    Oct 2009
    Location
    tathra nsw australia
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    8

    Default Re: Simple DataBase problems

    Quote Originally Posted by numbat View Post
    Are you looking for QTextEdit::toPlainText? Or QTextEdit::toHtml?

    QTextEdit::toPlainText looks like it
    Thanks for the reply

    BTW Happy New Year!!!!

    regards
    briang

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 09:30
  2. Multiple database connections
    By cyberboy in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2008, 17:56
  3. Database Master-Detail Entry Form
    By Phan Sin Tian in forum Newbie
    Replies: 4
    Last Post: 3rd February 2008, 15:31
  4. SQLITE database problems
    By phoenix in forum Newbie
    Replies: 3
    Last Post: 30th April 2007, 22:38
  5. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 18:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.