Unsolved QMAKE
-
I Want to run qmake but i have this error,how can it be solved
How can mysql Library be define and where exctly.
This is the error am getting when i run my application within qt creator.Any idea,as to why other databases are listed there only mysql is missing? -
Hi,
Did you check the myriad of forum posts related to building the MySQL plugin ?
-
@SGaist
I have not yet seen it -
-
See the docs: https://doc.qt.io/qt-5/sql-driver.html#qmysql-for-mysql-or-mariadb-5-and-higher
section "How to Build the QMYSQL Plugin on Windows"
-
@sierdzio thanks. Is it okay to use wampserve with qt application? Can it work properly?
-
-
Thanks for that.am trying to build mysql plugins using the instructions from qt documentation.But when i download mysql server all what i see is a .exe file which think its a setup but i cannont see the lib and the c connector shown in the example below where am i getting it wrong? am i downloading wrong mysql server or what?
-
Well, the download provided by Oracle will be an installer. Nothing stops you from getting an older version of the connector if that simplify your life. The MariaDB connector is also a good alternative.
-
-
what could be the meaning of the last two lines of this error?
-
You are storing a local QSqlDatabase object and are recreating a new connection that is replacing the one stored in the variable.
-
@SGaist So how can it be solved?
-
First thing, as the QSqlDatabase documentation explains: do not do that and if you remove the database connection, follow the documentation of the removeDatabase method..
-
Thanks,I gone through that documention,but still not clear,I uninstalled the mysql server which was connected to the app at first,but after trying to connect for second ,am facing that error.
The first connection used the default connection name. Am confused on how to desconnect the database with a default name.I have seen this function QSqldatabase::connectionName() but on how to use it am not sure.Please any help will be appreciated. -
How are you using QSqlDatabase in your code ?
-
@SGaist
Here is the code:QT += core gui sql printsupport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11
.h file
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include<QtSql> #include<QSqlDatabase> #include<QMessageBox> #include<mywork.h> //#include<payfee.h> QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); void closedb(); private slots: void on_LOGIN_clicked(); void on_REGISTER_clicked(); void on_LOGIN_2_clicked(); private: Ui::MainWindow *ui; QSqlDatabase database; }; #endif // MAINWINDOW_H
d.cpp file
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); ui->USERNAME_REG->setPlaceholderText("ENTER USERNAME"); ui->E_MAIL->setPlaceholderText("ENTER YOUR E-MAIL ADDRESS"); ui->PASSWORD_REG->setPlaceholderText("ENTER YOUR PASSWORD"); ui->PHONE->setPlaceholderText("ENTER PHONE NUMBER"); ui->USERNAME_LOGIN->setPlaceholderText("ENTER USERNAME"); ui->PASSWORD_LOGIN->setPlaceholderText("ENTER PASSWORD"); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_LOGIN_clicked() { QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("127.0.0.1"); db.setUserName("root"); db.setPassword(""); db.setDatabaseName("mysql"); if(db.open()) //database connections { QMessageBox::information(this,"connection","SYSTEM READY\nYOU CAN NOW REGISTER OR LOGIN!"); } else { QMessageBox::information(this,"not connected","SYSTEM NOT CONNECTED"); } } void MainWindow::on_REGISTER_clicked() { QString username = ui->USERNAME_REG->text(); QString email=ui->E_MAIL->text(); QString password =ui->PASSWORD_REG->text(); QString phone =ui->PHONE->text(); if(username=="" || email==""|| password==""||phone=="") { QMessageBox::warning(this,"warning","PLEASE ENTER ALL THE REQUIRED DETAILS"); } else {//checking to avoid duplication of data QSqlQuery query; query.prepare("SELECT USERNAME,EMAIL,PHONE FROM users WHERE USERNAME=:USERNAME AND EMAIL=:EMAIL AND PHONE=:PHONE"); query.bindValue(":USERNAME",username); query.bindValue(":EMAIL",email); query.bindValue(":PHONE",phone); if(query.exec()){ //QMessageBox::warning(this,"warninng","query successful!"); } if(query.size()>0){ QMessageBox::warning(this,"WARNING","CHECK YOUR NAME,E-MAIL OR PHONE NUMBER PLEASE\n" "ONE OF THESE HAVE BEEN USED BY OTHER USERS ALREADY!"); } // QSqlQuery qry; else { //running insert query QSqlQuery qry; qry.prepare("INSERT INTO users(USERNAME,EMAIL,PASSWORD,PHONE)" "VALUES(:USERNAME, :EMAIL, :PASSWORD, :PHONE)"); qry.bindValue(":USERNAME",username); qry.bindValue(":EMAIL",email); qry.bindValue(":PASSWORD",password); qry.bindValue(":PHONE",phone); if(qry.exec()) { QMessageBox::information(this,"WELCOME","YOU HAVE SUCCESSFULLY REGISTERED!\nYOU NOW LOGIN!"); } else { QMessageBox::warning(this,"WARNING!","PLEASE TURN ON THE SYSTEM!"); } } } } void MainWindow::on_LOGIN_2_clicked() { QString username=ui->USERNAME_LOGIN->text(); QString password=ui->PASSWORD_LOGIN->text(); QSqlQuery query(QSqlDatabase::database("Myconnect")); query.prepare("SELECT USERNAME,PASSWORD FROM users WHERE USERNAME=:USERNAME AND PASSWORD=:PASSWORD"); query.bindValue(":USERNAME",username); query.bindValue(":PASSWORD",password); if(!query.exec()){ //QMessageBox::warning(this,"warninng","PLEASE TURN ON THE SYSTEM!"); } if(query.size()>0){ //window two hide(); MYWORK work; work.setModal(true); work.exec(); } else { QMessageBox::warning(this,"CHENJEZO!","NOT SUCCESSFUL!\n" "TURN ON THE SYSTEM OR ENTER CORRECT DETAILS!"); } }
-
QSqlDatabase database;
As suggested already remove that (you do not even use it in the code you posted).
There is no need to keep QSqlDatabase instance (explained in the documentation).QSqlQuery query(QSqlDatabase::database("Myconnect")); - where do you actually add this database? Please read https://doc.qt.io/qt-5/qsqldatabase.html#database
"If no connectionName is specified the default connection is used. If connectionName does not exist in the list of databases, an invalid connection is returned."
" -
@jsulm
Thanks for your help .The Qsqldatabase database has been used in a difference class when calling for the instance database.But the main problem is that I can't connect to the database any more .am always told qmsql drivers not loaded.old connection removed.My am is to remove that old
connectionn so that I can connect to the database again. -
But why do you need to remove the connection in the first place ? Can't you just close it, update the information and open it again ?
How exactly are you using QSqlDatabase ?