Solved Login
-
I'm trying to login with levels but the levels are not working. Someone can help me?
I'm working with Qt 5.10.1 on Windows 10I'm trying to login with levels but the levels are not working. Someone can help me?
I'm working with Qt 5.10.1 on Windows 10
http://prntscr.com/jxy71z
http://prntscr.com/jxy7pp -
@123456789
What is your problem and what does this have to do with Qt?This is purely a question about your SQL query. Did you bother to examine
QSqlQuery::lastError()
when your query returned failure? (Hint: if you put an incomplete start-of-comment into a query string without an end-of-comment marker, what do you expect from SQL?) -
@JonB
I hope sqlite will confirm that level 1 exists with this password and username.
how to use QSqlQuery :: lastError ()? -
@123456789
I don't know what "level 1 exists" might mean.
Look at the docs to how to use it (it just returns a string).P.S.
While you are rewriting your query, you must not inject a raw string directly into a SQL statement without doing whatever to ensure it is correctly quoted. Especially with a password --- try having the password include a literal'
character, and see what happens.... One way would be to use theprepare()
&bindValue()
methods.P.P.S.
Rather than always giving us your code via a screenshot link --- which we have to click on, and we cannot copy out of --- please change over to pasting the code as text, which really should be quicker anyway. In your post, insert a line with ``` (3-backticks) at the start, then your code, then a line with same 3 backticks at the end. -
@JonB
I made it
[6_1529661500932_main.cpp](Uploading 100%) [5_1529661500932_login.ui](Uploading 100%) [4_1529661500932_login.h](Uploading 100%) [3_1529661500931_login.cpp](Uploading 100%) [2_1529661500931_ex3.pro.user](Uploading 100%) [1_1529661500930_ex3.pro](Uploading 100%) [0_1529661500930_este.sqlite](Uploading 100%)
https://we.tl/SuQp1qR8IM -
@123456789 You made what? We cannot see anything except
"[6_1529661500932_main.cpp](Uploading 100%) [5_1529661500932_login.ui](Uploading 100%) [4_1529661500932_login.h](Uploading 100%) [3_1529661500931_login.cpp](Uploading 100%) [2_1529661500931_ex3.pro.user](Uploading 100%) [1_1529661500930_ex3.pro](Uploading 100%) [0_1529661500930_este.sqlite](Uploading 100%)" -
@jsulm
i have not permissions
i use wi transfer -
@123456789
Permissions? To copy & paste code extracts into the text of your posts like I suggested? -
LOGIN.CPP
#include "login.h"
#include "ui_login.h"#define Path_to_DB "C:/Users/kss/Documents/ex3/este.sqlite"
login::login(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::login)
{
ui->setupUi(this);myDb = QSqlDatabase::addDatabase("QSQLITE"); myDb.setDatabaseName(Path_to_DB); QFileInfo checkFile(Path_to_DB); if (checkFile.isFile()) { if(myDb.open()) { ui->lblresult->setText("entrou"); } }else{ ui->lblresult->setText("not"); }
}
login::~login()
{
delete ui;
qDebug() <<"connect closed";
myDb.close();
}void login::on_pushButton_2_clicked()
{
ui->txtpass->setText("");
ui->txtuser->setText("");
}void login::on_pushButton_clicked()
{
QString Username, Password;
Username = ui->txtuser->text();
Password = ui->txtpass->text();
QString Rol1 = ui->cmbniveis->currentText();QSqlQuery qry; if(qry.exec("SELECT User, Password, Role FROM Users Where User=\'" + Username + "\' AND Password=\'" + Password + "\' /*AND Role=\'" + Rol1 + "\'" )) { if(qry.next()) { ui->lblresult->setText("Connectado"); QString msg = "Username = " + qry.value(0).toString() + "\n" + "Password = " + qry.value(1).toString(); "Role = " + qry.value(2).toString(); QMessageBox::warning(this, "Bem sucedido", msg); }else{ ui->lblresult->setText("errado"); } }
}
-
@123456789 said in Login:
/*AND
What is this?
Also use http://doc.qt.io/qt-5/qsqlquery.html#lastError to see what the error was. -
@JonB
help me please -
@123456789
Both I & @jsulm have indeed told you what you need to do/read up. In a forum like this you need to put some effort in yourself, nobody wants to keep writing your complete code for you, we have our own work to do too.... -
-
@123456789 When qry.exec() fails I would assume...
-
what @jsulm
-
if (qry.exec(...)) { ... } else { qDebug() << qry.lastError(); }
-