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. [SOLVED] Qt and sqlite problem
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Qt and sqlite problem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.7k 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.
  • A Offline
    A Offline
    advseo32
    wrote on last edited by
    #1

    Hi every body

    i'm using QSQLITE as DBMS

    so, every thing works fine, until now , i got an error "Driver not loaded"

    i'm using the same Database and it works with this code ( driver loaded perfectly )

    @ m_db = new QSqlDatabase;
    //**base de donnée traitement//

    *m_db = QSqlDatabase::addDatabase("QSQLITE") ;
    m_db->setHostName("localhost");
    m_db->setDatabaseName("gestionstockDB.db");
    m_db->setPassword("");
    m_db->setUserName("");
    if(m_db->open())
    {
        m_model->setQuery("select * from Produit");
        ui->tableView->setModel(m_model);
    
    }else
        QMessageBox::critical(this,"Erreur data base",m_db->lastError().text());@
    

    but when i want to instert data i got an error "Driver not loaded"

    @ m_query->prepare("insert into Produit (Reference,Designation,localisation,Famille,Qte_min,Qte_max,Qte_stock,Unite,Prix_achat,Prix_vente) VALUES(:ref,:design,:local,:fam,:qtmin,:qtmax,:qtstock ,:unite,:pachat,:pvente)");

                // santize data
    
                m_query->bindValue(":ref",ui->referenceLineEdit->text());  // QlineEdit
                m_query->bindValue(":design",ui->designationLineEdit->text()); // QlineEdit
                m_query->bindValue(":local",ui->localisaitonLineEdit->text()); // QlineEdit
                m_query->bindValue(":fam","Famille2"); // QcomboBox
                m_query->bindValue(":qtmin",ui->stockMinimaleLineEdit->text().toFloat()); // QlineEdit
                m_query->bindValue(":qtmax",ui->stockMaximaleLineEdit->text().toFloat()); // QlineEdit
                m_query->bindValue(":qtstock",ui->stockInitialeLineEdit->text().toFloat()); // QlineEdit
                m_query->bindValue(":unite","unite"); // QlineEdit
                m_query->bindValue(":pachat",ui->prixDAchatLineEdit->text().toFloat());  // QlineEdit
                m_query->bindValue(":pvente",ui->prixDeVenteLineEdit->text().toFloat());  // QlineEdit
                m_db->open();
                
                if(m_query->exec())
                {
                    QMessageBox::information(this,tr("Donnée insérer"),tr("les donnée sont insérer avec success")) ;
                }else{
                    QMessageBox::critical(this,tr("Requette Erreur"), m_query->lastError().text());
                }@
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      joejoshw
      wrote on last edited by
      #2

      Hello,

      I have just typed this, and it works OK:
      @
      QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
      db.setDatabaseName("C:/test.sb");
      if (!db.open()) {
      QMessageBox::critical(this, "Error", db.lastError().text());
      return;
      }

      QSqlQuery qu(db);
      qu.prepare("INSERT INTO Produit (Reference, Localisation, Famile) "
                 " VALUES (:ref, :local, :fam)");
      qu.bindValue(":ref", "Reference");
      qu.bindValue(":local", "Local");
      qu.bindValue(":fam", "Famile");
      
      if (qu.exec()) {
          QMessageBox::information(this, "OK", "Row Inserted");
      } else {
          QMessageBox::critical(this, "Error", qu.lastError().text());
      }
      

      @

      1 Reply Last reply
      0
      • A Offline
        A Offline
        advseo32
        wrote on last edited by
        #3

        [quote author="joejoshw" date="1376570605"]Hello,

        I have just typed this, and it works OK:
        @
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("C:/test.sb");
        if (!db.open()) {
        QMessageBox::critical(this, "Error", db.lastError().text());
        return;
        }

        QSqlQuery qu(db);
        qu.prepare("INSERT INTO Produit (Reference, Localisation, Famile) "
                   " VALUES (:ref, :local, :fam)");
        qu.bindValue(":ref", "Reference");
        qu.bindValue(":local", "Local");
        qu.bindValue(":fam", "Famile");
        
        if (qu.exec()) {
            QMessageBox::information(this, "OK", "Row Inserted");
        } else {
            QMessageBox::critical(this, "Error", qu.lastError().text());
        }
        

        @

        [/quote]
        yes you're right my error is her

        m_query !!

        i don't spesify the db in m_query intialisation
        @
        m_query = new Qsqlquery(); // this wrong
        mquery = new Qsqlquer(m_db) ; this is right@

        1 Reply Last reply
        0
        • J Offline
          J Offline
          joejoshw
          wrote on last edited by
          #4

          Good.

          Happy coding.

          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