briang
31st December 2009, 01:17
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.?????????
#include "dvd1.h"
#include "ui_dvd1.h"
Dvd1::Dvd1(QWidget *parent)
: QDialog(parent), ui(new Ui::Dvd1)
{
ui->setupUi(this);
if (QFile::exists("exdvd.sqlite")) {} // works ok
else {
setUpDb();
}
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(insertData()));
}
Dvd1::~Dvd1()
{
delete ui;
}
void Dvd1::setUpDb()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("exdvd.sqlite");
db.open();
QSqlQuery query = db.exec("CREATE TABLE IF NOT EXISTS table1"
"(id integer primary key,"
"title VARCHAR(60),"
"library VARCHAR(15),"
"number integer,"
"notes VARCHAR(500))");
QSqlError err = db.lastError();
if(!err.text().size() > 1)
QMessageBox::information(0,"Error creating database", err.text());
}
void Dvd1::insertData()
{
QString str = "Hello There";
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("exdvd.sqlite");
db.open();
// textDoc-> HOW TO GET textEdit TEXT TO textDoc???????????????????
// QSqlQuery query = db.exec("INSERT INTO 'table1' ('title', 'library', 'number', 'notes')" // works ok
// " VALUES ('UnTame Bunch The', 'Wish List', '24', str);");
QSqlQuery query;
query.prepare("INSERT INTO table1 (title, library, number, notes) " // works ok
"VALUES (:title, :library, :number, :notes)");
//query.bindValue(":title", "Chicken Little");
query.bindValue(":title", ui->lineEdit->text()); //OK
query.bindValue(":library", "Main");
//query.bindValue(":number", 1010);
query.bindValue(":number",ui->lineEdit_2->text()); //OK number field integer yet takes lineEdit.text???
query.bindValue(":notes", str); // works ok
// query.bindValue(":notes", textDoc->WHAT?????????????HOW???????????
if(!query.exec())
{
QSqlError err1=query.lastError(); // works checks query.prepare ONLY????
QMessageBox::information(this,"Query Error",err1.text());
}
}
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
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.?????????
#include "dvd1.h"
#include "ui_dvd1.h"
Dvd1::Dvd1(QWidget *parent)
: QDialog(parent), ui(new Ui::Dvd1)
{
ui->setupUi(this);
if (QFile::exists("exdvd.sqlite")) {} // works ok
else {
setUpDb();
}
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(insertData()));
}
Dvd1::~Dvd1()
{
delete ui;
}
void Dvd1::setUpDb()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("exdvd.sqlite");
db.open();
QSqlQuery query = db.exec("CREATE TABLE IF NOT EXISTS table1"
"(id integer primary key,"
"title VARCHAR(60),"
"library VARCHAR(15),"
"number integer,"
"notes VARCHAR(500))");
QSqlError err = db.lastError();
if(!err.text().size() > 1)
QMessageBox::information(0,"Error creating database", err.text());
}
void Dvd1::insertData()
{
QString str = "Hello There";
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("exdvd.sqlite");
db.open();
// textDoc-> HOW TO GET textEdit TEXT TO textDoc???????????????????
// QSqlQuery query = db.exec("INSERT INTO 'table1' ('title', 'library', 'number', 'notes')" // works ok
// " VALUES ('UnTame Bunch The', 'Wish List', '24', str);");
QSqlQuery query;
query.prepare("INSERT INTO table1 (title, library, number, notes) " // works ok
"VALUES (:title, :library, :number, :notes)");
//query.bindValue(":title", "Chicken Little");
query.bindValue(":title", ui->lineEdit->text()); //OK
query.bindValue(":library", "Main");
//query.bindValue(":number", 1010);
query.bindValue(":number",ui->lineEdit_2->text()); //OK number field integer yet takes lineEdit.text???
query.bindValue(":notes", str); // works ok
// query.bindValue(":notes", textDoc->WHAT?????????????HOW???????????
if(!query.exec())
{
QSqlError err1=query.lastError(); // works checks query.prepare ONLY????
QMessageBox::information(this,"Query Error",err1.text());
}
}
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