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. Sqlite database not working
Qt 6.11 is out! See what's new in the release blog

Sqlite database not working

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.7k Views 2 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.
  • K Offline
    K Offline
    karthi shan
    wrote on last edited by
    #1

    i am facing some issue on updating mydata base. If have anyone idea regarding this please hepl me.

    here is my code
    #include "login.h"
    #include "ui_login.h"

    login::login(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::login)
    {
    ui->setupUi(this);

    }

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

    void login::on_pushButton_clicked()
    {

    PRINT<<"Connecting ....";

    QSqlDatabase myDB= QSqlDatabase::addDatabase("QSQLITE");
    myDB.setDatabaseName("/home/embdestech/Desktop/tsk/testdatabase.db");
    //db.setDatabaseName("/testdatabase.db");

    if(myDB.open())//opening database
    {
    PRINT <<"Database Opened";
    QSqlQuery qry;

    if(qry.exec("CREATE TABLE karthick(name VARCHAR[20],addr VARCHAR[20]);"))
    {
    PRINT <<"karthick Table Created...";
    }

    if(qry.exec("INSERT INTO karthick(name,addr) VALUES('hgdhjs','jfgd');"))
    {
    PRINT <<"values inserted sucessfully...";
    }
    else
    {
    PRINT <<"user Error .." << qry.lastError().text();
    PRINT <<"Closed";
    myDB.close();

        }
    

    myDB.close();

    }
    }

    M 1 Reply Last reply
    0
    • K karthi shan

      i am facing some issue on updating mydata base. If have anyone idea regarding this please hepl me.

      here is my code
      #include "login.h"
      #include "ui_login.h"

      login::login(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::login)
      {
      ui->setupUi(this);

      }

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

      void login::on_pushButton_clicked()
      {

      PRINT<<"Connecting ....";

      QSqlDatabase myDB= QSqlDatabase::addDatabase("QSQLITE");
      myDB.setDatabaseName("/home/embdestech/Desktop/tsk/testdatabase.db");
      //db.setDatabaseName("/testdatabase.db");

      if(myDB.open())//opening database
      {
      PRINT <<"Database Opened";
      QSqlQuery qry;

      if(qry.exec("CREATE TABLE karthick(name VARCHAR[20],addr VARCHAR[20]);"))
      {
      PRINT <<"karthick Table Created...";
      }

      if(qry.exec("INSERT INTO karthick(name,addr) VALUES('hgdhjs','jfgd');"))
      {
      PRINT <<"values inserted sucessfully...";
      }
      else
      {
      PRINT <<"user Error .." << qry.lastError().text();
      PRINT <<"Closed";
      myDB.close();

          }
      

      myDB.close();

      }
      }

      M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      1. do you see any error??
      2. is PRINT a macro?
      3. was the karthick table created?

      you have to provide more information

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        To add to @mcosta, you don't do anything if the database failed to open, you should also at least log a message there.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • K Offline
          K Offline
          karthi shan
          wrote on last edited by
          #4

          Thanks for your suggestion , Now database its working.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What was the problem ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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