Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

read and save number from sqlite



  • I've made a login dialog and i want check if the id & pass that input in the dialog is right , and sae the id of the user

    so i've made class :

    class users
    {
    public:
        static int id;
    };
    

    and the functuin:

    void LoginDialog::on_OK_clicked()
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("SalesManagement.db");
        QSqlQuery query("SELECT * FROM [main].[users]");
        users user;
        while (query.next())
        {
            if (query.value(1) == ui->username_input->text() &&
                   query.value(2) ==  ui->password_input->text())
            {
                user.id = query.value(0).toInt();
                break;
            }
        }
        ui->label_3->setText(QString::number(user.id));
    }
    

    but i get this error :

    alt textb12b81d0d27d99f5.png))


  • Qt Champions 2017

    Show us your users class and the definition of users::id. Usually you'd get this error if you haven't defined the static variable.



  • read the topic again i've already include the users class in the topic


  • Qt Champions 2017

    @MrLibya
    Do you have a definition for this static member in your cpp? Something like this:

    int users::id = 0;
    
    // ... 
    void LoginDialog::on_OK_clicked()
    {
        // ...
    }
    


  • This post is deleted!

  • Lifetime Qt Champion

    Hi,

    You're not opening your database and also not doing any checks to see whether your query ran successfully.

    Also, since you are only giving the name of the database file, it will be created in the same folder as the application unless you already provide that file.


Log in to reply