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] SQLite Error: No such table!
Forum Update on Monday, May 27th 2025

[SOLVED] SQLite Error: No such table!

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 29.0k Views
  • 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.
  • S Offline
    S Offline
    suggi87
    wrote on 2 Dec 2014, 08:36 last edited by
    #1

    Hello,

    I made a new sqlite database named auto.db with one table named autos(varchar(50),varchar(50),varchar(50),real,integer)
    I have also insert one dataset.

    If i use cmd.exe i can execute the sql statement which is in my code.
    In QT there is no such table autos???

    this is my code in the constructor:

    @
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("C:/sqlite/auto.db");
    db.open();

    if(!db.open())
        ui->label_25->setText("FAILED TO OPEN THE DB");
    else
        ui->label_25->setText("CONNECTED DB");
    
    QSqlQuery query1;
    query1.exec("SELECT name FROM autos WHERE kraftstoff = 'Diesel'");
    qDebug(&#41; << query1.size(&#41;;
    qDebug() << query1.isSelect();
    qDebug() << query1.isValid();
    qDebug() << query1.lastError();
    
    while(query1.next())
    {
    QString name = query1.value(0).toString();
    qDebug() << name;
    }
    

    @

    and thats my console:

    -1
    false
    false
    QSqlError("1", "Unable to execute statement", "no such table: autos")

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p3c0
      Moderators
      wrote on 2 Dec 2014, 11:00 last edited by
      #2

      Hi,

      1. No need to open database twice. Instead you can do this
        @
        bool isOpened = db.open();
        if(isOpened) {
        qDebug() << "opened;
        } else {
        qDebug() << "Error";
        }
        @

      2. Try printing the error in else part to get the exact error.

      3. Try passing the current database to QSqlQuery as
        @
        QSqlDatabase db = QSqlDatabase::database;
        QSqlQuery query1(db);
        query1.exec("SELECT name FROM autos WHERE kraftstoff = 'Diesel'");
        @

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        suggi87
        wrote on 2 Dec 2014, 14:31 last edited by
        #3

        Do I have to install any drivers for sqlite additional to QT Creator?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          suggi87
          wrote on 2 Dec 2014, 19:12 last edited by
          #4

          Here is my solution:

          It was the database path. i used auto instead of auto.db

          @
          QString dbName="C:/sqlite/auto";
          @

          1 Reply Last reply
          1

          1/4

          2 Dec 2014, 08:36

          • Login

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