#include <QtSql/QSqlDatabase>
#include <QMessageBox>
#include <QString>
#include <QApplication>
bool ConnectDb( const QString& hostName,
const QString& dbName,
const QString& usrName,
const QString& pwd )
{
db.setHostName( hostName );
db.setDatabaseName( dbName );
db.setUserName( usrName );
db.setPassword( pwd );
return db.open();
}
int main( int argc, char** argv )
{
bool dbConnected = ConnectDb( "osmanthus-desktop", "MYDB",
"mysql", "godfather1943@" );
if( dbConnected )
{
}
else
{
}
return app.exec();
}
#include <QtSql/QSqlDatabase>
#include <QMessageBox>
#include <QString>
#include <QApplication>
bool ConnectDb( const QString& hostName,
const QString& dbName,
const QString& usrName,
const QString& pwd )
{
QSqlDatabase db = QSqlDatabase::addDatabase( QString( "QMYSQL" ) );
db.setHostName( hostName );
db.setDatabaseName( dbName );
db.setUserName( usrName );
db.setPassword( pwd );
return db.open();
}
int main( int argc, char** argv )
{
QApplication app( argc, argv );
bool dbConnected = ConnectDb( "osmanthus-desktop", "MYDB",
"mysql", "godfather1943@" );
if( dbConnected )
{
QMessageBox::information( 0, QString( "Message" ),
QString( "DB Connected" ) );
}
else
{
QMessageBox::information( 0, QString( "Message" ),
QString( "DB Not Connected!" ) );
}
return app.exec();
}
To copy to clipboard, switch view to plain text mode
QSqlDatabase: QMYSQL driver not loaded
To copy to clipboard, switch view to plain text mode
Bookmarks