PDA

View Full Version : Looking for a really basic database example



N3wb
4th January 2011, 03:24
I've done a little PHP programming before, so I'm at least a little familiar with SQL syntax, but I'm struggling to understand how to use a database with QT. All of the examples I've been able to find have been really complicated and I was hoping that someone could post (or link to) just a really basic example of how to interact with a local database?

For instance, I've tried the following:


QSqlDatabase db;

db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
if (db.open())
{
QSqlQuery query;
qDebug()<<"\n**** db opened**** :";
qDebug()<<query.exec("create table person (id int primary key, "
"firstname varchar(20), lastname varchar(20))");
}

But the application output is:


**** db opened**** :
false

I can't seem to get anything to work..

Thanks for your help :)

tbscope
4th January 2011, 04:23
Make sure that the create table syntax is correct with respect to SQLite.