Parameter count mismatch on MacOS (Sqlite)
-
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"; } }
-
Please check the return values of the sqlquery functions - esp. QSqlQuery::prepare() and check that the two column names are really available.