Answer the question
In order to leave comments, you need to log in
Qt. How to connect a db?
Unable to connect database
#include <QtWidgets>
#include <QtSql>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication App(argc,argv);
MainWindow *Window = new MainWindow;
Window->show();
QSqlDatabase db = QsqlDatabase::addDatabase("QMYSQL","mydb");
db.setHostName("localhost");
db.setDatabaseName("institute");
db.setUserName("root");
db.setPassword("1234");
bool ok = db.open();
int result = App.exec();
delete Window;
return result;
}
A:\QtProjects\Lab_Part_2\main.cpp:12: ошибка: 'QsqlDatabase' has not been declared
QSqlDatabase db = QsqlDatabase::addDatabase("QMYSQL","mydb");
^
QT += sql
did, Ctrl+Click refers to qsqldatabase.h
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question