-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+"'"))
拥有原始指针?有智能指标或简单的成员变量。 –