-5
"'+'は2つのポインタを追加できません。エラー: '+'は2つのポインタを追加できません
誰かが私に正確に間違っていることを説明できますか、それを解決する方法はありますか?
情報:movedbは、User_ID(整数)とパスワード(テキスト)を含むテーブルユーザーです。私は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 ");
}
}
-line:
if(qry.exec("select * from user where User_ID='"+username+"' AND password'"+password+"'"))
は生のポインタを所有している:
しかし、良いアイデアは、このような状況を避けるために、あなたのクエリを準備するのですか?スマートポインタまたは単純なメンバ変数があります。 –