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. QSqlQuery::prepare: no driver
Forum Updated to NodeBB v4.3 + New Features

QSqlQuery::prepare: no driver

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.5k 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.
  • R Offline
    R Offline
    rizoritis
    wrote on 31 Jan 2014, 23:24 last edited by
    #1

    Hello,

    I am trying to update a row in my database however when I call the following function I get an error that says "QSqlQuery::prepare: no driver".

    @void PointsModel::setCellData(int row, QString name, QString x, QString y, QString z, QString theta)
    {
    database->query->prepare("UPDATE points SET (name, x, y, z, a) VALUES (:name, :x, :y, :z, :a) WHERE id = :id");
    database->query->bindValue(":id", row);
    database->query->bindValue(":name", name);
    database->query->bindValue(":x", x);
    database->query->bindValue(":y", y);
    database->query->bindValue(":z", z);
    database->query->bindValue(":a", theta);
    database->query->exec();
    }@

    I am doing other queries to the database such as SELECT, etc. So I don't know why this doesn't work. Any thoughts???

    Thanks!

    H 1 Reply Last reply 19 Mar 2017, 11:13
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 1 Feb 2014, 02:02 last edited by
      #2

      At a guess, the database variable is pointing to a QSqlDatabase object that has not had QSqlDatabase::addDatabase() called on it beforehand.

      Really though, you do not need to be persistently storing QSqlDatabase references or QSqlQuery objects, or allocating them on the heap in the first place.

      1 Reply Last reply
      2
      • R Offline
        R Offline
        rizoritis
        wrote on 3 Feb 2014, 14:34 last edited by
        #3

        [quote author="ChrisW67" date="1391220132"]At a guess, the database variable is pointing to a QSqlDatabase object that has not had QSqlDatabase::addDatabase() called on it beforehand.

        Really though, you do not need to be persistently storing QSqlDatabase references or QSqlQuery objects, or allocating them on the heap in the first place.[/quote]

        I did call addDatabase() in the constructor. I did the following:

        @ db = QSqlDatabase::addDatabase( "QSQLITE" );
        db.setDatabaseName( "../database" );

        if ( !db.open() )
        {
            qDebug() << "Failed to connect to database: " + db.lastError().text();
            return false;
        }
        
        qDebug() << "Successfully connected to database...";
        
        query = new QSqlQuery(db);@
        
        1 Reply Last reply
        0
        • R Offline
          R Offline
          rizoritis
          wrote on 3 Feb 2014, 14:51 last edited by
          #4

          Just as an a test I implemented the following line before my queries to "re-register" the driver:

          @database->query = new QSqlQuery(database->db);@

          It got rid of the no driver error, however having to make a new query for each call I make doesnt seem right. Also, When looking into the database, it does not see to add anything to it, even if I call commit.

          1 Reply Last reply
          0
          • R rizoritis
            31 Jan 2014, 23:24

            Hello,

            I am trying to update a row in my database however when I call the following function I get an error that says "QSqlQuery::prepare: no driver".

            @void PointsModel::setCellData(int row, QString name, QString x, QString y, QString z, QString theta)
            {
            database->query->prepare("UPDATE points SET (name, x, y, z, a) VALUES (:name, :x, :y, :z, :a) WHERE id = :id");
            database->query->bindValue(":id", row);
            database->query->bindValue(":name", name);
            database->query->bindValue(":x", x);
            database->query->bindValue(":y", y);
            database->query->bindValue(":z", z);
            database->query->bindValue(":a", theta);
            database->query->exec();
            }@

            I am doing other queries to the database such as SELECT, etc. So I don't know why this doesn't work. Any thoughts???

            Thanks!

            H Offline
            H Offline
            HNBeginner
            wrote on 19 Mar 2017, 11:13 last edited by
            #5

            @rizoritis i noticed that in qt: if you setdatabaseName and give it a correct path but with an incorrect database-name; qt creates an empty database and when you try to retrieve data in that database and because it is empty qt gives the error QSqlQuery::prepare: no driver: in short if you have an already existing database make sure you spell it correctly otherwise first create tables and then insert data in order to retrieve, update etc.

            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