Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7755455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:34:24+00:00 2026-06-01T12:34:24+00:00

QSqlDatabase db = QSqlDatabase::addDatabase(QSQLITE); db.setDatabaseName(:temp:); if (!db.open()) { qDebug() << Database open error. <<

  • 0
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":temp:");

if (!db.open()) {
    qDebug() << "Database open error." << db.lastError();
    return;
}

QSqlQuery query(db);
query.prepare("create table if not exists dew (id int, title varchar(255) not null)");
if (!query.exec()) {
    qDebug() << "Query exec error. " << query.lastError();
    return;
}
qDebug() << "Insert query exec OK";

if (!query.exec("insert into dew(id, title) values (1, 'hello')")) qDebug() << query.lastError();

Shows the output as

Insert query exec OK 
QSqlError(1, "Unable to execute statement", "table dew has no column named id") 
Insertion finished. 

Table creation seems to be OK. But where is id field? I’m confused with this code. I test query.record().contains(“id”); and it is false

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:34:26+00:00Added an answer on June 1, 2026 at 12:34 pm

    ":temp:" is not a valid name for a temporary database, this creates a regular database on disk which stays after the database connection is closed.

    To create a temporary or an in-memory sqlite database, that won’t be saved to a file, you need to pass respectively an empty string (*) or the special string ":memory:" as the database name.

    http://www.sqlite.org/inmemorydb.html

    Qt doesn’t allow an empty QString as the database name, but a QString starting with a '\0' should work: db.setDatabaseName(QChar(0));

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a SQLite database from qt like this: QSqlDatabase db = QSqlDatabase::addDatabase(QSQLITE,
My application uses Qt SQL this way QSqlDatabase db = QSqlDatabase::addDatabase(QODBC); db.setDatabaseName(DRIVER={Microsoft Access Driver
bool MainWindow::initDb() { db = QSqlDatabase::addDatabase(QSQLITE); // defined on class header as QSqldatabase db
#include <QtGui> #include <QtSql> #include <QApplication> class ABC { public: QSqlDatabase db; QSqlQuery memberQuery;
My application accesses an Oracle database through Qt's QSqlDatabase class. I'm compiling Qt as
I'm trying to create a custom function for a SQLite database I'm using with
I have the following very basic stored procedure: CREATE PROCEDURE [dbo].[GetNumberToProcess] AS RETURN 999
Hi I'm trying to create an sqldatabase and I'm trying to define my foreign
I've got the following problem with QODBC driver: bool Dialog::createOdbcConnection(QSqlDatabase * db, QString odbcName,QString
I am dealing with Sql Server and Oracle through Qt, when using QSqlDatabase::transaction() on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.