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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:13:33+00:00 2026-06-14T02:13:33+00:00

The following code fails on QSqlQuery::exec() . When I run the query without the

  • 0

The following code fails on QSqlQuery::exec(). When I run the query without the prepared statement argument, it returns the correct results, available as one would expect through QSqlQuery::next()

executedQuery() reports that ":username" was in fact not replaced by the argument, but with a ? (Is it supposed to, since the query did not execute successfully?).

db_ is a QSqlDatabase class variable and isOpen() reports true. The Qt framework verison is 4.7.3.

DBSql::userInfo(const QString &username, 
                QString &passwd, 
                QString &name, 
                UserPriv priv)
{
  QSqlQuery userQuery(db_);
  const QString userStr("SELECT u.id, u.fullname, u.password, p.description \
                        FROM users u INNER JOIN privilege p ON u.privilege_id = p.id \
                      WHERE u.username = :username");
  userQuery.bindValue(":username", username);

  if (!userQuery.prepare(userStr))
    std::cout << "prepare failed" << std::endl;

  if (userQuery.exec()) {
    while (userQuery.next()) {
      userId = userQuery.value(0).toInt();
      name = userQuery.value(1).toString();
      passwd = userQuery.value(2).toString();
      const QString privilegeDesc = userQuery.value(3).toString();
    }
  }
}
  • 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-14T02:13:35+00:00Added an answer on June 14, 2026 at 2:13 am

    You have to call userQuery->prepare(userStr) before userQuery->bindValue(":username", username)

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

Sidebar

Related Questions

The following code fails to run on Python 2.5.4: from matplotlib import pylab as
I have the following code that fails when i run it. my .h file:
The following code fails in 'Evaluate' with: This expression was expected to have type
The following code fails to compile #include <iostream> #include <cmath> #include <complex> using namespace
Can anyone tell me why the following code fails to submit the form into
I can't figure out why the following code fails: # test.ps1 `$args: ($args) `$args
The following code compiles in Visual C++ and gcc, but fails with Code Warrior
The following code snippet on SQL server 2005 fails on the ampersand '&': select
If I use strict mode the following code does not work. It fails on
The following code fails to compile, producing a Widget must be a non-abstract type

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.