Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QMAKE



  • I Want to run qmake but i have this error,how can it be solved
    Capture5.PNG
    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?

    Capture6.PNG


  • Lifetime Qt Champion

    Hi,

    Did you check the myriad of forum posts related to building the MySQL plugin ?



  • @SGaist
    I have not yet seen it



  • @SGaist said in QMAKE:

    Hi,

    Did you check the myriad of forum posts related to building the MySQL plugin ?

    Do you have any link to that?You can help if you have


  • Moderators

    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?


  • Lifetime Qt Champion

    Hi,

    @GREYON said in QMAKE:

    wampserve

    It's a MySQL stack, as long as you have the MySQL plugin, no problem.



  • 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?

    Capture6.PNG


  • Lifetime Qt Champion

    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.



  • @SGaist said in QMAKE:

    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.

    Thanks



  • what could be the meaning of the last two lines of this error?

    Capture7.PNG


  • Lifetime Qt Champion

    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?


  • Lifetime Qt Champion

    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..



  • @SGaist

    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.


  • Lifetime Qt Champion

    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!");
    
       }
    
         }
    

  • Lifetime Qt Champion

    @GREYON said in QMAKE:

    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.


  • Lifetime Qt Champion

    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 ?



  • @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!");
    
      }
       }
    
    }
    }
    

  • Lifetime Qt Champion

    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.



  • @tmapp
    Okay thanks for your help,am just not clear on how to remake drivers .


  • Lifetime Qt Champion

    @GREYON said in QMAKE:

    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



  • @tmapp said in QMAKE:
    I cannot see this line below in my code

    QMAKE_USE +=


Log in to reply