You are not logged in.

1

Thursday, July 1st 2004, 8:06pm

Loading an ODBC driver in Qt

I am trying to connect to a MS SQL database on our network from my Linux Machine (Mandrake 10.0 with Samba and Qt Designer 2.3).

I downloaded the ODBC driver from unixODBC.org and the ODBC-ODBC bridge from Easysoft.com. I unzipped them both and put the folders in /usr/local/. After installing and making them, and doing the necesary configuration, I was able to connect to the database through typing the isql command in the shell.

Now I am trying to connect to the MS SQL database in a Qt App. So I go to Project->Database Connections and try and make a new database connection, but when I try and connect it says that driver is not loaded. This may have something to do with the fact that there is nothing in "file:/usr/lib/qt3/plugins/sqldrivers". I really have no idea though. Anyway good anybody tell me what is going wrong with the driver and how I can connect to the database.

And I'm new to this linux stuff so please go easy.

Thanks a lot.

rhg

Trainee

  • "rhg" is male

Posts: 178

Location: Velbert, Germany

Occupation: senior software developer

  • Send private message

2

Friday, July 2nd 2004, 1:12pm

Please look here regarding the method Qt uses to locate its plugins:
http://doc.trolltech.com/3.3/plugins-howto.html

Regarding SqlServer, I found that FreeTDS works a lot better than odbc-odbc from Easysoft. Just a suggestion :)

3

Friday, July 2nd 2004, 4:23pm

so I installed FreeTDS on my system and was able to connect to the host with the database by using

tsql -H 10.250.1.233 -p 1622 -U sa

I looked through that plugin tutorial link, but again, I'm very new to this and had trouble applying it to myself. What exactly do I have to do from Qt to make an application that connects to my database.

Thanks Again.

Sanjay

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

4

Friday, July 2nd 2004, 10:04pm

RE: Loading an ODBC driver in Qt

Look in your distro packages if Qt database plugins are not separated entities. It's the case with Fedora Core, where all plugins are in the form qt-MySQL, qt-ODBC and so on.
And database plugins are not insalled by default. If I remember, Mandrake does the same packaging.
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

5

Tuesday, July 6th 2004, 2:08pm

Thanks for the help...

Now if the ODBC driver isn't installed, how do I install them?

zlatko

Professional

  • "zlatko" is male

Posts: 728

Location: Ukraine,Lviv

Occupation: programmer

  • Send private message

6

Tuesday, July 6th 2004, 2:45pm

just use QDatabase class without Projects->DatabaseConnections
a life without programming its alike empty bottle 8)

djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

7

Tuesday, July 6th 2004, 5:05pm

qDebug( QSqlDatabase::drivers().join( "\n" ) ) ;

will show installed drivers.

If not installed, have a look into your Mandrake RPMS. You should find something like qt-ODBC-xxx.rpm, qt-MySQL-xxx.rpm, qt-PostgreSQL-xxx.rpm.

RedHat, Fedora, Mandrake, Yellow Dog and many others package Qt in pieces. So you only install needed drivers. But as they do not document this, you can seek for a while in the CDs before finding what you need.
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

8

Tuesday, July 6th 2004, 5:07pm

I'm sorry for my ignorance, I'm really new to this...

But my Qt doesnt have a QDatabase class. Also, do any of you have example code that might push me in the right direction.

Thanks a lot

zlatko

Professional

  • "zlatko" is male

Posts: 728

Location: Ukraine,Lviv

Occupation: programmer

  • Send private message

9

Wednesday, July 7th 2004, 8:36am

sorry
QSqlDatabase

my example :

Source code

1
2
3
4
5
6
7
8
9
10
11
QSqlDatabase *m_DBSirius;


  m_DBSirius = QSqlDatabase::addDatabase("QODBC3");
   m_DBSirius->setDatabaseName(m_DBName);
   m_DBSirius->setUserName(m_DBUserName);
   m_DBSirius->setPassword(m_DBPassword);
   m_DBSirius->setHostName(m_DBHostName);

  if (!m_DBSirius->open())
   return FALSE;


and then use class QSqlQuery for INSERT,SELECT or UPDATE data from
your database
a life without programming its alike empty bottle 8)