本文整理汇总了C++中QSqlDriver::isOpenError方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlDriver::isOpenError方法的具体用法?C++ QSqlDriver::isOpenError怎么用?C++ QSqlDriver::isOpenError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlDriver
的用法示例。
在下文中一共展示了QSqlDriver::isOpenError方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loader
/**
* The constructor creates the db and the tables if required. There's a single instance of db for all
* the ServerDatabase instances.
*/
ServerDatabase::ServerDatabase() {
#ifdef _VERBOSE_DATABASE
qDebug() << "Creating a new instance of the db connector: " << m_dbref;
#endif
if (!m_dbref++) {
// manually load the driver (for some reason I couldn't figure out how to have it loaded automagically)
QPluginLoader loader("libqsqlmysql.so");
if (loader.load()) {
#ifdef _VERBOSE_DATABASE
qDebug() << "Loaded mysql drivers plugin";
#endif
} else {
qDebug() << QObject::tr("Failed to load mysql drivers plugin: ") + loader.errorString();
return;
}
QSqlDriverPlugin *sqlPlugin = qobject_cast<QSqlDriverPlugin *>(loader.instance());
#ifdef _VERBOSE_DATABASE
qDebug() << "Available sql drivers: " << sqlPlugin->keys();
#endif
QSqlDriver *sqlDriver = sqlPlugin->create(DB_TYPE);
if (!sqlDriver) {
qDebug() << QObject::tr("Failed to instantiate mysql driver");
return;
}
sqlDriver->open(DB_NAME, DB_USR, DB_PWD, DB_HOST);
if (sqlDriver->isOpenError()) {
qDebug() << QObject::tr("Failed to connect to (") + DB_TYPE + QObject::tr(") DB ") + DB_NAME + QObject::tr(" on host ") + DB_HOST + QObject::tr(" with usr/pwd '") + DB_USR + "/" + DB_PWD + "'";
qDebug() << QObject::tr("ERROR: ") + sqlDriver->lastError().text();
return;
}
m_db = QSqlDatabase::addDatabase(sqlDriver);
// create tables if non existing
createTables();
}
}