Unsolved QMAKE
-
@SGaist
I don't really want to remove the connection,its like it became unconnected when i unistalled qt5 .9.9 and installal qt 5.12.5, i tried to install qt 5.9.9 but it did not become connected again.on how QSqlDatabase is being used,It was used to create an object database which is being called when i want to access the database .below is an example of how it has been used.
private slots: void on_LOGIN_clicked(); void on_REGISTER_clicked(); void on_LOGIN_2_clicked(); private: Ui::MainWindow *ui; QSqlDatabase database;
MUSIC, CLASS.
#include "music.h" #include "ui_music.h" MUSIC::MUSIC(QWidget *parent) : QDialog(parent), ui(new Ui::MUSIC) { ui->setupUi(this); ui->SURNAME->setPlaceholderText("ENTER SURNAME"); ui->GRADE->setPlaceholderText("INTER GRADE, e.g 9"); ui->CLASS->setPlaceholderText("ENTER CLASS e.g 9A"); ui->AMOUNT->setPlaceholderText("ENTER AMOUNT e.g 100"); ui->OTHERNAME->setPlaceholderText("ENTER OTHER NAME(S)"); } MUSIC::~MUSIC() { delete ui; } void MUSIC::on_ENTER_FEE_clicked() { QString surname =ui->SURNAME->text(); QString lastname=ui->OTHERNAME->text(); QString clas= ui->CLASS->text(); QString amount=ui->AMOUNT->text(); QString grade =ui->GRADE->text(); QString date=ui->DATE->text(); if(surname=="" || grade==""|| clas==""||amount==""||lastname==""||date=="") { QMessageBox::warning(this,"warning","PLEASE ENTER ALL THE REQUIRED DETAILS"); } else { QSqlDatabase::database(); QSqlQuery query; query.prepare("SELECT SURNAME,LASTNAME FROM music WHERE SURNAME=:surname AND LASTNAME=:lastname"); query.bindValue(":surname",surname); query.bindValue(":lastname",lastname); if(query.exec()){ //QMessageBox::warning(this,"warninng","query successful!"); } if(query.size()>0){ QMessageBox::warning(this,"WARNING","THE NAME HAS BEEN ENTERED ALREADY!\nUSE INITIAL IF ITS A DIFFERENT NAME!"); } // QSqlQuery qry; else { query.prepare("INSERT INTO music (SURNAME,LASTNAME,GRADE,CLASS,AMOUNT,DATE)" "VALUES(:SURNAME, :LASTNAME, :GRADE, :CLASS, :AMOUNT, :DATE)"); query.bindValue(":SURNAME",surname); query.bindValue(":GRADE",grade); query.bindValue(":CLASS",clas); query.bindValue(":AMOUNT",amount); query.bindValue(":LASTNAME",lastname); query.bindValue(":DATE",date); if(query.exec()) { QMessageBox::information(this,"inserted","PAYMENTS RECORDED SUCCESSFULLY!"); } else { QMessageBox::warning(this,"warning","PAYMENT NOT RECORDED!"); } } } }
-
Do not keep a QSqlDatabase member variable.
It's explained in the class documentation. -
Hi,
- your first error was due to : QMAKE_USE += mysql in mysql.pro
Comment it and everything will move to the next step - your second error: was due to the qmysql driver (missing driver or not compatible with your version)
- it is Ok to use QT with wampp mysql ( i'm using it with xampp )
- remake the driver, and that will solve the issue of : QMYSQL driver not loaded
- follow this reply you will achieve the connection :: Tested Solution
good luck.
- your first error was due to : QMAKE_USE += mysql in mysql.pro
-
@tmapp
Okay thanks for your help,am just not clear on how to remake drivers . -
am just not clear on how to remake drivers .
RTM: https://doc.qt.io/qt-5/sql-driver.html#building-the-drivers or search the forum.
-
@Christian-Ehrlicher
Okay thanks -