Results 1 to 2 of 2

Thread: Looking for a really basic database example

  1. #1
    Join Date
    Aug 2009
    Location
    United States
    Posts
    45
    Thanks
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Looking for a really basic database example

    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:

    Qt Code:
    1.  
    2. db = QSqlDatabase::addDatabase("QSQLITE");
    3. db.setDatabaseName("test.db");
    4. if (db.open())
    5. {
    6. QSqlQuery query;
    7. qDebug()<<"\n**** db opened**** :";
    8. qDebug()<<query.exec("create table person (id int primary key, "
    9. "firstname varchar(20), lastname varchar(20))");
    10. }
    To copy to clipboard, switch view to plain text mode 

    But the application output is:
    **** db opened**** :
    false
    I can't seem to get anything to work..

    Thanks for your help
    Last edited by N3wb; 4th January 2011 at 03:32.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Looking for a really basic database example

    Make sure that the create table syntax is correct with respect to SQLite.
    Last edited by tbscope; 4th January 2011 at 04:33.

Similar Threads

  1. Need help with basic Qt
    By doforumda in forum Qt Programming
    Replies: 5
    Last Post: 10th July 2010, 08:53
  2. Need basic help
    By Ossi in forum Qwt
    Replies: 2
    Last Post: 23rd October 2009, 13:24
  3. a basic questions!!
    By unix7777 in forum Newbie
    Replies: 1
    Last Post: 28th March 2009, 19:10
  4. Need immediate help on basic cpp
    By Sandip in forum General Programming
    Replies: 10
    Last Post: 21st September 2008, 10:33
  5. Qt/C++ basic Q-s
    By jamadagni in forum General Programming
    Replies: 9
    Last Post: 10th February 2006, 08:01

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.