-5
出現錯誤「'+'無法添加兩個指針」。錯誤:'+'無法添加兩個指針
任何人都可以解釋我什麼是錯的/如何解決它?
信息:movedb獲取包含User_ID(整數)和密碼(文本)的表用戶。現在生成錯誤的行,之前返回false,所以我認爲User_ID不能與類型(Qstring和整數)進行比較,並進行轉換。
login.cpp
#include "login.h"
#include "ui_login.h"
Login::Login(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
db=QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setUserName("root");
db.setPassword("");
db.setDatabaseName("movedb");
if(!db.open())
{
ui->Status->setText("Status: Failed to connect with database");
}
else
{
ui->Status->setText("Status: Ready to LogIn");
}
}
Login::~Login()
{
delete ui;
}
void Login::on_Login_2_clicked()
{
int username;
QString password;
username=ui->lineEdit_Username->text().toInt();
password=ui->lineEdit_Password->text();
if(!db.isOpen())
{
qDebug()<<"Failed to open database";
return;
}
QSqlQuery qry;
if(qry.exec("select * from user where User_ID='"+username+"' AND password'"+password+"'"))
{
int count=0;
while(qry.next())
{
count++;
}
if(count==1)
{
ui->Login_status->setText("You have logged in");
}
if(count>1)
{
ui->Login_status->setText("Something went wrong - please contact with admin");
}
if(count<1)
{
ui->Login_status->setText("Failed to LogIn");
}
}
else
{
ui->label->setText("Something is very Wrong ");
}
}
直插產生錯誤:
if(qry.exec("select * from user where User_ID='"+username+"' AND password'"+password+"'"))
擁有原始指針?有智能指標或簡單的成員變量。 –