PDA

View Full Version : access SQlite from Qt (Windows & Linux)



Qt Coder
20th July 2009, 08:11
Hi all,

I m using Qt 4.4.3 on Windoes XP.
I have developed an application ,now I want to use SQLite database fro storing some fields.

Can anyone help me out in things like

1) from where to download SQLite .
2) How to access SQLite database from Qt.

3) The final application would be ported to Linux,so tell me which database to be used so that it would be compatible with Linux also.

spirit
20th July 2009, 08:24
Qt already supports SQLite "from the box" and this driver available by default when Qt has been built.

Qt Coder
20th July 2009, 08:37
But how to start building database,from where to download SQLite>?

"from the box" ????????? (dint understand)

spirit
20th July 2009, 08:45
all what you need it's a build Qt with SQLite suppport, SQLite driver are located in QTDIR/src/3rdparty/sqlite.
"from the box" -- by default.

Qt Coder
20th July 2009, 08:57
I m still not getting how would I create my database.....

In the path you told there are 3 files

1)shell.c
2)sqlite3.c
3)sqlite.h


How to use these files for creating my database??

Or is there any other GUI provided for creating database?????

nish
20th July 2009, 09:01
there is no GUI in sqlite+Qt world.. (thats why its "lite").. you have to code in everything...
first you need to configure Qt with sqlite support (see configure help for this).
then learn the QtSql module.. (its a matter of just how fast u can read the docs).
then create teh database and/or read it.(in c++/Qt code).

spirit
20th July 2009, 09:06
sigh, to create a database you need to specify a database name using QSqlDatabase::setDatabaseName, a database file will be created in current directory and its name will be equal to database name.
PS. take a look into QTDIR/examples/sql/connection.h, if you change


db.setDatabaseName(":memory:");

to


db.setDatabaseName("mydatabase");

then all data will be kept in a file insted of RAM.

ChrisW67
20th July 2009, 11:09
You can get a basic command line tool to manipulate Sqlite databases from the Sqlite site:
http://sqlite.org
This tool can be very useful when you first start an Sqlite database project.

You can also create and manipulate databases within the code of your Qt application. As others have pointed out you only need to use a Qt library built with Sqlite support (e.g. any of the Qt Creator SDK downloads).

jpujolf
21st July 2009, 08:57
If you want a "graphical interface" can also use this one.

SQLiteman (http://sourceforge.net/projects/sqliteman/)

Made with Qt, so works in Linux/Unix, Win, Mac...

Qt Coder
21st July 2009, 13:29
I had installed SQLIteman.

created one database and one table in it.

Nos how to connect to this database from Qt?????

jpujolf
21st July 2009, 13:47
Take a look at this (http://doc.qtsoftware.com/4.5/qsqldatabase.html)

Also you can look at here (http://www.qtcentre.org/forum/f-qt-programming-2/t-qt-sqlite-connection-8380.html) or here (http://www.qtcentre.org/forum/f-qt-programming-2/t-qt-how-to-connect-to-sqlite-db-file-20430.html)

And from now on, before asking so basic things :

- Read at least Qt's documentation here (http://doc.qtsoftware.com/4.5/index.html)
- Google a little or search Qt centre ( I've done a simple search : sqlite connect and got me 24 results )

And please, please, please : don't open TWO threads asking the same and don't ignore the answers people gently gives to you ( as here (http://www.qtcentre.org/forum/f-qt-programming-2/t-steps-to-connect-to-sqlite-from-q-22172.html) )

Thanks.

Qt Coder
22nd July 2009, 08:48
When I created a new database in sQLiteman.then first it asked me to store one file .

I hav attached that file herewith.......

Now my question is ,how my qt application would recognize where my database is located...

Do I hav to place this at path executable resides.....

nish
22nd July 2009, 09:36
please man... take a look at qtassistant... search for qt sql module... its very easy task

SunnySan
22nd July 2009, 11:07
If you want a "graphical interface" can also use this one.

SQLiteman (http://sourceforge.net/projects/sqliteman/)

Made with Qt, so works in Linux/Unix, Win, Mac...

thanks for the link Sqliteman is a great open source SQL application.