Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, March 2002
QMYSQLDriver problem


Message 1 in thread

Hi!

Look at my code below. Is there a way to connect to mysql server without 
specify the database name?

  1: #include <qapp.h>
  2: #include <qsqldatabase.h>
  3: #include <iostream>
  4:
  5: int main( int argc, char** argv ) {
  6:   QApplication a(argc, argv);
  7:   QSqlDatabase* db = QSqlDatabase::addDatabase("QMYSQL3");
  8:   if (db) {
  9:      db->setDatabaseName("");
10:      db->setUserName("root");
11:      db->setPassword("xxxx");
12:      if (!db->open())
13:         cout << db->lastError().databaseText() << endl;
14:      cout << db->isOpen() << endl;
15:   }
16:
17:   return 0;
18: }

On line 9, if I dont call this function the application gerenates a 
segmentation fault.

Way do we need use the mysql function mysql_select_db in QMYSQLDriver 
code? The mysql function mysql_real_connect can select a database 
without fail if we dont specify one.

Thanks.
-- 
 [ signature omitted ]