Friday 15 April 2011

c++ - QtSql connection -


I am trying to create a connection in the database and let the database insert / delete / query I know SQL well but can not wrap my head around it in QT. I used to program in Delphi.

This is my code so far:

  QSqlDatabase db; Db.addDatabase ("QSQLITE"); Db.setHostName ("localhost"); // I do not know if I should include it, then the database is in the same directory as my program db.setDatabaseName ("Xmato.odb"); Db.setUserName (""); // no username is db.setPassword (""); // no password is db.open (); Db.prepare ("select from member"); Db.exec ();   

I've added it to my .pro file:

  QT + = sql;   

QtSql included in my main file.

When I run this code, I get an error:

  QSqlQuery :: ready: do not open the database   

Any thoughts would greatly appreciate me.

PS: I use C ++ on Linux Ubuntu 12.04 and use LibreOffice Base to create my database.

After some little google-ing - Internal Database of OpenOffice Libraries HSQLDB (Option for natural java). .

It appears that some versions of the OpenLife Base are also able to connect, I recommend installing some settings that are more accessible to C ++, especially Qt.

This means that depending on the usage of the database, anyone may need to obtain additional source code (or packages) and a plugin / DLL / compilation library The QtSql module is dynamically loaded (i.e. run-time). I have participated in it for this.

When you receive all that setup, then the call should match the type of database to add you.

  QSqlDatabase:: AddDatabase ("QODBC"); // MSSQL QSqlDatabase :: addDatabase ("QSQLITE") for something like; // SQLite QSqlDatabase :: addDatabase ("QMYSQL"); // MySQL for   

Individually, if you are doing this only for kick, then a quick and easy database is SQLite

No comments:

Post a Comment