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 8933985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:40:50+00:00 2026-06-15T09:40:50+00:00

I recently started with the Qt Creator and C++ and wanted to use a

  • 0

I recently started with the Qt Creator and C++ and wanted to use a PostgreSQL database for my needs. So I figured out how to get the driver, included all the tags needed and started executing some querys.

I created new tables, inserted some data, updated them afterwards. It all worked just fine, until I tried to simply select some rows. The query just ended without an error-message and a response of NULL.

The command was a simple SELECT-Command:

query = db.exec("SELECT id FROM users WHERE name = 'Testuser';");

But a basic SELECT doesn’t work either:

query = db.exec("SELECT * FROM users;");

If I now copy exactly this query and put it as a SQL-Statement directly into pgAdmin, it works just fine and responses with the user-id.

I tried quotation marks for the tablename, I tried the full row-names (SELECT users.id FROM public.users WHERE users.name = 'Testuser';) and large and small letters because of some tips from google – nothing worked.

Every query works just fine, but if I try a SELECT, it just always responses with NULL. Although every single of this SELECT-Querys works just fine in pgAdmin.

Has anyone an idea?

The following tags are used:

#include <QDebug>
#include <QtCore/QCoreApplication>
#include <QtSql/QPSQLDriver>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QCryptographicHash>
#include <QSqlError>

The full code looks like this:

QString response;
QSqlQuery query;
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");

db.setHostName("127.0.0.1");
db.setPort(5432);
db.setDatabaseName("postgres");
db.setUserName("postgres");
db.setPassword("password");

if (db.open())
{
    query = db.exec("SELECT id FROM users WHERE name = 'Testuser';");
    response = query.value(0).toString();
}

db.close();
  • 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-15T09:40:53+00:00Added an answer on June 15, 2026 at 9:40 am

    Qt Assisstant says:

    After the query is executed, the query is positioned on an invalid
    record and must be navigated to a valid record before data values can
    be retrieved (for example, using next()).

    So, you should do this to get its first record:

    query.first();
    QString result = return query.record().value(0).toString();
    

    Also you can iterate over its records:

    QStringList results;
    while (query.next())
    {
        QString result = return query.record().value(0).toString();
        results.append(result);
    }
    

    And it’s always a good idea to check query execution error status:

    bool res = query.exec(...);
    if (res == false)
    {
        qDebug() << "SQL ERROR: " << query->lastError().text();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We recently started making use of the new Google Expansion APK mechanism. Overall it
I recently started using LINQ to SQL in my database later for a C#
I recently started reading up on the out-of-browser ability of Silverlight 3. I also
I recently started to use linux, so I have little knowledge about it. At
I recently started a project where the team decided we'd like to use jQuery
I´ve recently started looking a web service calls using PHP. I can´t get the
I recently started on creating a 'game' using PHP and a mysql database. In
I recently started learning C# and im stuck with a gridview and database .
I recently started creating apps for android and wanted to test layouts for different
I recently started to use the Nodewords module in Drupal 6. This adds the

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.