Answer the question
In order to leave comments, you need to log in
How to properly connect MySQL to Qt5.4?
The problem is quite hackneyed, but still, I ask for help, I'm stuck in this very much.
Downloaded installed.
After the operations that were not done quite accurately, due to the inaccuracy of the instructions, I decided to compile a code example.
I get that there seems to be a driver for QMYSQL, but I still get an error.
I would be incredibly grateful for step-by-step instructions on how to fix and still connect the DBMS to Qt.
//main.cpp
#include "widget.h"
#include <QApplication>
#include<QSqlDatabase>
#include<QSql>
#include<QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qDebug() << QSqlDatabase::drivers();
Widget w;
w.show();
return a.exec();
}
//widget.cpp конструктор
#include "widget.h"
#include "ui_widget.h"
#include<QDebug>
#include<QSql>
#include<iterator>
#include<QSqlDatabase>
#include<QSqlQuery>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("mysql");
db.setUserName("root");
db.setPassword("rootPW");
if (!db.open()) qDebug() << "Failed to connect to root mysql admin";
ui->textEdit->setReadOnly(true);
}
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