include QCoreApplication include QtSql include QDebug int main int arg

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <QCoreApplication>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={SQL SERVER};Server=ALEXANDER\SQLEXPRESS;Database=lab1;User ID=user1234;Password=1234;Trusted_Connection=yes;");
if(!db.open())
{
qDebug()<<db.lastError().text();
return 0;
}
return a.exec();
}