Home > Mobile >  QT for realizing the function of registration
QT for realizing the function of registration

Time:12-05

Database to use sqlite, didn't learn c + + in a row,
 
void ZCJM: : on_pushButton_clicked ()
{
If (UI - & gt; RadioButton_3 - & gt; IsChecked ())
{
QString sqlite1;
QString sqlite2;

Uname=UI - & gt; LineEdit - & gt; The text ();
QString passwd=UI - & gt; LineEdit_2 - & gt; The text ();


QSqlQueryModel * model1=new QSqlQueryModel;

//QSqlQueryModel * model2=new QSqlQueryModel;

Sqlite1="select count (*) from student where name='" + uname +"' ";
Model1 - & gt; SetQuery (sqlite1);
QModelIndex index1=model1 - & gt; The index (0, 0);
If (index1. Data ()==0)
{
QMessageBox: : about (NULL, "prompt", "user registration success");
Sqlite2="insert into student (name, password) values ('" + uname + "', '" + passwd +") ";
QSqlQueryModel * model=new QSqlQueryModel;
The model - & gt; SetQuery (sqlite2);
}
Else if (index, 1. The data ()!=0)
{
QMessageBox: : about (NULL, "prompt", "user already exists");
}
}

}
How to implement the registered function? Lineedit how to obtain the value of the imported sqlite form?

CodePudding user response:

You insert a database of user information, there is this user in the database, the next time the login directly from the database query the corresponding information, there is already registered

CodePudding user response:

 
QString name=UI - & gt; LineEdit - & gt; The text ();
QString STR=QString (" insert into student (name) values (' % 1 ') "). Arg (name);
QSqlQuery query;
Query. The exec (STR);

So you wrote in the database

CodePudding user response:

 
QString SQL="INSERT INTO student (name, password) VALUES (: name, password)";
QString name=UI - & gt; LineEdit - & gt; The text ();
QString password=UI - & gt; LineEdit - & gt; The text ();//here is the Password should be handle hash or any other way, don't definitely save
QSqlQuery query (database);//assume that the database has been set up the connection information
Query. Prepare (sqlMap [" AddFileInfo] ");
Query. BindValue (" : name ", name);
Query. BindValue (" : "",");
Bool success=query. The exec ();
If (success!=true)
{
QDebug () & lt; & lt;" Insert the fileInfo error. The error: "& lt; }

I recently spun off in a project, a parameterized SQL statements to prevent SQL injection and improve efficiency,
  •  Tags:  
  • Qt
  • Related