[SOLVED] SQLite Error: No such table!

  • 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");

        ui->label_25->setText("FAILED TO OPEN THE DB");
        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();
    QString name = query1.value(0).toString();
    qDebug() << name;


    and thats my console:

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

  • Moderators


    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'");

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

  • Here is my solution:

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

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.