Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Parameter count mismatch on MacOS (Sqlite)

Parameter count mismatch on MacOS (Sqlite)

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 217 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fernando992013
    wrote on last edited by
    #1

    I'm working on a class project with QT Creator (CMake). The project was written in Windows 11, however, when I try to use it on MacOS I get the error of "Parameter count mismatch". I get this error when attempting to login on my program. I type in the password and username but nothing happens besides getting the last qdebug message (the one for query.exec().

    The program builds, and runs just fine and the database connects and runs but it seems like the query statements won't run.
    It works just fine on windows. I'm not familiar with Mac. Is there something I have to do different?

    This is the mydb.cpp file.

    #include "mydb.h"
    
    MyDB* MyDB::instance = nullptr;
    
    MyDB::MyDB()
    {
        init();
    }
    void MyDB::init()
    {
        db = QSqlDatabase::addDatabase("QSQLITE", "Data");
        db.setDatabaseName("bookstore.db");
    
        if(QFile::exists("bookstore.db"))
                qDebug() << "DB file exist";
            else
               qDebug() << "DB file doesn't exists";
    
            if (!db.open())
                qDebug() << db.lastError().text();
            else
                qDebug() << "Database loaded successful!";
    
    }
    
    MyDB *MyDB::getInstance()
    {
        qDebug() << "in MyDB::getInstance()";
    
        if(instance == nullptr)
            instance = new MyDB();
    
        return instance;
    
    }
    
    QSqlDatabase MyDB::getDBInstance()
    {
        return db;
    }
    
    void MyDB::ResetInstance()
       {
          delete instance;
          instance = nullptr;
       }
    
    MyDB::~MyDB()
    {
       db.close();
    }
    
    

    This is the loginform.cpp file.

    #include "loginform.h"
    
    #include <QMessageBox>
    #include "mydb.h"
    #include "ui_loginform.h"
    
    
    LoginForm::LoginForm(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::LoginForm) // Change 'new Ui::loginform' to 'new Ui::LoginForm'
    {
        ui->setupUi(this);
        // Disconnect any existing connections
           disconnect(ui->btnLogin, &QPushButton::clicked, nullptr, nullptr);
        connect(ui->btnLogin, &QPushButton::clicked, this, &LoginForm::on_btnLogin_clicked);
    }
    
    
    LoginForm::~LoginForm()
    {
        delete ui;
    }
    
    
    
    void LoginForm::on_btnLogin_clicked()
    {
        QString username = ui->txtUsername->text();
        QString pass = ui->txtPass->text();
        QSqlQuery query(MyDB::getInstance()->getDBInstance());
        query.prepare(QString("SELECT UserID FROM customerLogin WHERE Username = :username AND Password = :pass"));
        query.bindValue(":username", username);
        query.bindValue(":pass", pass);
    
        if(query.exec())
        {
            if(query.next())
            {
                qDebug() << "Login successful " << query.value(0).toString();
                hide();
                mainwindow = new MainWindow(this);
                mainwindow->show();
            }
            else
            {
                qDebug() << "Login unsuccessful";
                QMessageBox::warning(this, "Incorrect Login", "Incorrect password or username. Try again.");
            }
        }
        else
        {
            qDebug() << "Login unsuccessful";
        }
    }
    
    Christian EhrlicherC 1 Reply Last reply
    0
    • F fernando992013

      I'm working on a class project with QT Creator (CMake). The project was written in Windows 11, however, when I try to use it on MacOS I get the error of "Parameter count mismatch". I get this error when attempting to login on my program. I type in the password and username but nothing happens besides getting the last qdebug message (the one for query.exec().

      The program builds, and runs just fine and the database connects and runs but it seems like the query statements won't run.
      It works just fine on windows. I'm not familiar with Mac. Is there something I have to do different?

      This is the mydb.cpp file.

      #include "mydb.h"
      
      MyDB* MyDB::instance = nullptr;
      
      MyDB::MyDB()
      {
          init();
      }
      void MyDB::init()
      {
          db = QSqlDatabase::addDatabase("QSQLITE", "Data");
          db.setDatabaseName("bookstore.db");
      
          if(QFile::exists("bookstore.db"))
                  qDebug() << "DB file exist";
              else
                 qDebug() << "DB file doesn't exists";
      
              if (!db.open())
                  qDebug() << db.lastError().text();
              else
                  qDebug() << "Database loaded successful!";
      
      }
      
      MyDB *MyDB::getInstance()
      {
          qDebug() << "in MyDB::getInstance()";
      
          if(instance == nullptr)
              instance = new MyDB();
      
          return instance;
      
      }
      
      QSqlDatabase MyDB::getDBInstance()
      {
          return db;
      }
      
      void MyDB::ResetInstance()
         {
            delete instance;
            instance = nullptr;
         }
      
      MyDB::~MyDB()
      {
         db.close();
      }
      
      

      This is the loginform.cpp file.

      #include "loginform.h"
      
      #include <QMessageBox>
      #include "mydb.h"
      #include "ui_loginform.h"
      
      
      LoginForm::LoginForm(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::LoginForm) // Change 'new Ui::loginform' to 'new Ui::LoginForm'
      {
          ui->setupUi(this);
          // Disconnect any existing connections
             disconnect(ui->btnLogin, &QPushButton::clicked, nullptr, nullptr);
          connect(ui->btnLogin, &QPushButton::clicked, this, &LoginForm::on_btnLogin_clicked);
      }
      
      
      LoginForm::~LoginForm()
      {
          delete ui;
      }
      
      
      
      void LoginForm::on_btnLogin_clicked()
      {
          QString username = ui->txtUsername->text();
          QString pass = ui->txtPass->text();
          QSqlQuery query(MyDB::getInstance()->getDBInstance());
          query.prepare(QString("SELECT UserID FROM customerLogin WHERE Username = :username AND Password = :pass"));
          query.bindValue(":username", username);
          query.bindValue(":pass", pass);
      
          if(query.exec())
          {
              if(query.next())
              {
                  qDebug() << "Login successful " << query.value(0).toString();
                  hide();
                  mainwindow = new MainWindow(this);
                  mainwindow->show();
              }
              else
              {
                  qDebug() << "Login unsuccessful";
                  QMessageBox::warning(this, "Incorrect Login", "Incorrect password or username. Try again.");
              }
          }
          else
          {
              qDebug() << "Login unsuccessful";
          }
      }
      
      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please check the return values of the sqlquery functions - esp. QSqlQuery::prepare() and check that the two column names are really available.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved