Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Database and qt [☺SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Database and qt [☺SOLVED]

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yakine
    wrote on last edited by
    #1

    hello evreybody
    please help

    ther is my code
    @#ifndef LOGINWINDOW_H
    #define LOGINWINDOW_H

    #include <QMainWindow>
    #include <QtSql>
    #include<QtDebug>
    #include<QFileInfo>
    namespace Ui {
    class loginWindow;
    }

    class loginWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit loginWindow(QWidget *parent = 0);
    ~loginWindow();

    private slots:
    void on_pushButton_clicked();

    private:
    Ui::loginWindow *ui;
    QSqlDatabase db;
    };

    #endif // LOGINWINDOW_H@

    mainwindow.cpp

    @#include "loginwindow.h"
    #include "ui_loginwindow.h"
    using namespace std;
    #define q2c(string) string.toStdString()
    loginWindow::loginWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::loginWindow)
    {
    ui->setupUi(this);
    //conection a la base de donnees
    db= QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("yaki");
    if(!db.open())

        ui->stats->setText("fail to open the database");
    
    else
    ui->stats->setText("connected");
    
    }
    

    loginWindow::~loginWindow()
    {
    delete ui;
    }

    void loginWindow::on_pushButton_clicked()
    {
    QString username,password;
    username=ui->username->text();
    password=ui->password->text();
    if(!db.isOpen())
    {
    qDebug()<<"fail to open";
    return;

    }
    QSqlQuery query;
    if (query.exec&#40;"SELECT*FROM utilisateur WHERE identificateur='"+username+"'and
    

    password='"+password+"'"))
    {
    int count(0);
    while(query.next()){
    count++;

        }
        if (count==1)
            ui->stats->setText("bravo login");
    }
    

    }@

    so am trying to creat a login window but this part of code don't work

    @void loginWindow::on_pushButton_clicked()
    {
    QString username,password;
    username=ui->username->text();
    password=ui->password->text();
    if(!db.isOpen())
    {
    qDebug()<<"fail to open";
    return;

    }
    QSqlQuery query;
    if (query.exec&#40;"SELECT*FROM utilisateur WHERE identificateur='"+username+"'&& password='"+password+"'"&#41;&#41;
    {
        int count(0&#41;;
        while(query.next()){
            count++;
    
        }
        if (count==1)
            ui->stats->setText("bravo login");
    }
    

    }@

    there are an somthing rong in the last part of the code because wfen i run the project there is no error evrything is right but when i pressed the login button after i inter the username and the password the label don't change

    IF YOU HAVE MERCY ON PEOPLE GOD HAVE MERCY ON YOU

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      There should be space between "SELECT", "*" and "FROM", and also around "and", in your query. "&&" is not validSQL.

      You should look at lastError() when the query exec() fails.

      BTW: You should use bind variables in the query rather than building a string the way you have. Ponder what would happen if I entered this as as the password: @whatever' OR 1=1 @

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yakine
        wrote on last edited by
        #3

        HI
        THANK YOU CHRISw67

        IF YOU HAVE MERCY ON PEOPLE GOD HAVE MERCY ON YOU

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved