24,854
社区成员
发帖
与我相关
我的任务
分享
bool MyWin::login(const QString &strName, const QString &strPwd)
{
if (ui.lineEdit_1->text().isEmpty() || ui.lineEdit_2->text().isEmpty())
{
return false;
}
QFile info("D:\\user.txt");
if (!info.open(QIODevice::ReadOnly))
{
Message * message = new Message;
message->info("Connect fail!");
message->show();
return false;
}
QString Q_info = {};
QStringList QL_info;
while (!info.atEnd())
{
Q_info = info.readLine();
QL_info = Q_info.split("-", QString::SkipEmptyParts);
//此处if第二个条件,提示密码不匹配
if ( (QL_info.at(0) == strName) && (QL_info.at(1) == strPwd) )
{
info.close();
return true;
}
}
info.close();
return false;
}
bool MyWin::login(const QString &strName, const QString &strPwd)
{
//输入信息为空时,登录失败
if (strName.isEmpty() || strPwd.isEmpty())
{
return false;
}
QFile info("D:\\user.txt");
if (!info.open(QIODevice::ReadOnly))
{
Message * message = new Message;
message->info("Connect fail!");
message->show();
return false;
}
QString name, password;
while (!info.atEnd())
{
QTextStream line(info.readLine());
line >> name >> password;
if ((name == strName) && (password == strPwd))
{
return true;
}
}
return false;
}
if ( (QL_info.at(0) == strName) /*&& (QL_info.at(1) == strPwd)*/ )
{
Message * message = new Message;
message->info(QL_info.at(1)); //这里打印出来的内容和预期的密码一样,但是内容明明一样,为什么不能用==,会不会和const或者size有关?
message->show();
return true;
}
Q_info = info.readLine();
QL_info = Q_info.split("-", QString::SkipEmptyParts);
//此处if第二个条件,提示密码不匹配
if ( (QL_info.at(0) == strName) && (QL_info.at(1) == strPwd) )
{
info.close();
return true;
}
这里strPwd是111111,不知道QL_info.at(1)的内容是多少,期望的是111111