(QT 版本为5.3.2)
1.新建空的Qt项目,项目名为:databaseDriver
2.往项目中添加新的main.cpp文件
3.在databaseDriver.pro文件中添加如下一行代码:
QT += sql
QT += widgets
#include <QApplication>
#include <QSqlDatabase>
#include <QDebug>
#include <QStringList>
int main(int argc,char *argv[])
{
QApplication a(argc,argv);
qDebug() << "Available drivers: ";
QStringList drivers = QSqlDatabase::drivers();
foreach(QString driver,drivers)
{
qDebug() << driver;
}
return a.exec();
}
输出:
Available drivers:
“QSQLITE”
“QMYSQL”
“QMYSQL3”
“QODBC”
“QODBC3”
“QPSQL”
“QPSQL7”