zoukankan      html  css  js  c++  java
  • Linux QT数据库之登录注册

    视频链接:https://www.bilibili.com/video/av11673511/

    main.cpp

    #include <QSqlDatabase>
    #include <QSqlQuery>
     QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("dbname");
        db.open();
        QString s=QString("create table user(name varchar(10) primary key,passwd varchar(10))");
        QSqlQuery query;
        query.exec(s);
     Widget w;
        myDialog d;
        if(d.exec()==myDialog::Accepted)
        {
            w.show();
            return a.exec();
        }

    mydialog.cpp

    #include <QSqlQuery>
    #include <ui_mydialog.h>
    #include "QMessageBox"
    void myDialog::on_pushButton_clicked()
    {
        QString uname=ui->lineEdit->text();
        QString upasswd=ui->lineEdit_2->text();
        QString s=QString("select * from user where name=='%1' and passwd=='%2' ").arg(uname).arg(upasswd);
        QSqlQuery query;
        query.exec(s);
        if(query.first())
        {
            accept();
        }
        else
        {
            QMessageBox::warning(this,tr("Waring"),tr("pleaer register"),QMessageBox::Yes);
            ui->lineEdit->clear();
            ui->lineEdit_2->clear();
            ui->lineEdit->setFocus();
        }
    }
    
    void myDialog::on_pushButton_2_clicked()
    {
        QString uname=ui->lineEdit->text();
        QString upasswd=ui->lineEdit_2->text();
        QString s=QString("insert into user values ('%1' ,'%2') ").arg(uname).arg(upasswd);
        QSqlQuery query;
        bool d=query.exec(s);
        QMessageBox box;
        if(d)
        {
            box.setText("register success");
            box.exec();
            ui->lineEdit->clear();
            ui->lineEdit_2->clear();
            ui->lineEdit->setFocus();
        }
    }
  • 相关阅读:
    笛卡尔树学习笔记
    图论基础(自认为很全)
    我的博客在这里
    C++学习资料
    test
    个人介绍
    CF1153F Serval and Bonus Problem
    【ZJOI2020】抽卡
    【LOJ】小 Q 的序列
    我的个人博客:https://xyix.github.io
  • 原文地址:https://www.cnblogs.com/yunquan/p/7079299.html
Copyright © 2011-2022 走看看