ok
now here is something new.
i have made a new project called book.pro
following is the code for it :
bool createConnections()
{
// create the default database connection
if ( ! defaultDB )
{
qWarning( "Failed to connect to driver" );
return FALSE;
}
defaultDB->setDatabaseName( "mysql" );
defaultDB->setUserName( "root" );
defaultDB->setPassword( "" );
defaultDB->setHostName( "localhost" );
if ( ! defaultDB->open() ) {
qWarning( "Failed to open mysql database: " +
defaultDB->lastError().driverText() );
qWarning( defaultDB->lastError().databaseText() );
return FALSE;
}
return TRUE;
}
int main( int argc, char **argv )
{
QDataTable tb(0,"Author Table");
BookForm w;
int i=0;
if ( ! createConnections() )
{
i=1;
return 1;
qWarning("This is my warning. Error is in createConnection(). i=%d",i);
}
// w.show();
// tb.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
bool createConnections()
{
// create the default database connection
QSqlDatabase *defaultDB = QSqlDatabase::addDatabase( "QMYSQL3" );
if ( ! defaultDB )
{
qWarning( "Failed to connect to driver" );
return FALSE;
}
defaultDB->setDatabaseName( "mysql" );
defaultDB->setUserName( "root" );
defaultDB->setPassword( "" );
defaultDB->setHostName( "localhost" );
if ( ! defaultDB->open() ) {
qWarning( "Failed to open mysql database: " +
defaultDB->lastError().driverText() );
qWarning( defaultDB->lastError().databaseText() );
return FALSE;
}
return TRUE;
}
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QDataTable tb(0,"Author Table");
BookForm w;
int i=0;
if ( ! createConnections() )
{
i=1;
return 1;
qWarning("This is my warning. Error is in createConnection(). i=%d",i);
}
// w.show();
// tb.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
To copy to clipboard, switch view to plain text mode
i have included following header files :
qapplication.h , qsqldatabase.h , qsqlrecord.h , qsqlfield.h , qdatatable.h , "form1.h"
as usual the exe is formed without any errors. u can try it if you want.
in the form i have a qdatatable.
now in mysql bydefault there is a database called "mysql"
i have tried to use that.
while creating qdatatable all the tables in the database "mysql" were listed and i have selected "help_category" table.
inside this table there are various entries already present.
when i preview the form , all the entries are listed as it is.
but when i run the program from the shell the following error comes :
[root@localhost book]# ./book
QSqlCursor::setName: unable to build record, does 'help_category' exist?
QSqlRecord::field: index out of range: 0
QSqlRecord::position: unable to find field name
QSqlRecord::field: index out of range: -1
QSqlRecord::field: index out of range: 1
QSqlRecord::position: unable to find field parent_category_id
QSqlRecord::field: index out of range: -1
QSqlRecord::field: index out of range: 2
QSqlRecord::position: unable to find field url
QSqlRecord::field: index out of range: -1
QSqlRecord::field: index out of range: 3
QSqlRecord::position: unable to find field help_category_id
QSqlRecord::field: index out of range: -1
QSqlRecord::field: index out of range: 0
QSqlRecord::position: unable to find field name
QSqlRecord::field: index out of range: -1
QSqlRecord::field: index out of range: 1
QSqlRecord::position: unable to find field parent_category_id
QSqlRecord::field: index out of range: -1
QSqlRecord::field: index out of range: 2
QSqlRecord::position: unable to find field url
QSqlRecord::field: index out of range: -1
QSqlRecord::field: index out of range: 3
QSqlRecord::position: unable to find field help_category_id
QSqlRecord::field: index out of range: -1
QSqlDatabase warning: QMYSQL3 driver not loaded
QSqlDatabase: available drivers:
Failed to open mysql database: Driver not loaded
Driver not loaded
[root@localhost book]#
i dont know what is wrong here.
pleeese check the code. i think it is not able to access the database. but as i can see all the fields of mysql when i preview the form, so i think there is no problem with the driver.
please do something. one problem gone, another came. i m frustrated now!!:confused:
this really sucks
Bookmarks