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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:57:05+00:00 2026-05-24T20:57:05+00:00

I have used the query.next() function inside my code, but its returning false. I

  • 0

I have used the query.next() function inside my code, but its returning false.
I even checked in the database, there are 4 records present. But the code shows only one.
However if i use query.next() before the code of query.valid() then it doesn’t show any record
Please help

  qDebug() << "entering payment: get all the unchecked invoices for user: " + user;
  QStringList tmp;
  QSqlQuery query(m_storageUserManager->database());
  m_storageUserManager->dumpTable(m_invoiceInfoTable);
  m_storageUserManager->dumpTable(m_invoiceUserTable);
  qDebug()<<"THE NAME OF THE INVOICE USER TABLE_----=-----------------"<<m_invoiceInfoTable;
  qDebug()<<"THE NAME OF THE INVOICE USER TABLE_----=-----------------"<<m_invoiceUserTable;
  query.prepare("SELECT invoice FROM "+ m_invoiceInfoTable +" WHERE invoice = (SELECT
                 invoice FROM "+ m_invoiceUserTable +" WHERE user=:user)");
//  query.prepare("SELECT invoice FROM " + m_invoiceInfoTable + ","+ m_invoiceUserTable +" WHERE " + m_invoiceInfoTable + ".user = " + m_invoiceUserTable + ".:user");
  query.bindValue(":user", user);
  query.exec();
  query.first();
  qDebug()<<"Unchecked invoices done!!! " ;
  if(query.isValid()) {
    do {
      tmp.append(query.value(0).toString());    //as the value returned by value() is a QVariant so we need to change it to String.
    } while(query.next());
  } else
    tmp.append("No Unchecked invoice in the database");
  return tmp;
  • 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-05-24T20:57:06+00:00Added an answer on May 24, 2026 at 8:57 pm

    To check if the query was successful you should test the return value of either QSqlQuery::exec() or QSqlQuery::isActive() before trying to call first/next/last (when you pass the query string to the constructor of QSqlQuery, the query is already executed, so, you need to use QSqlQuery::isActive()).

    first(), next() and last() return true if they positioned the query on a valid record, you don’t have to test isValid() separately. Since first() is a positioning function too, you can read the value without calling next() directly after, unless you want to skip the first record.

    Since you may want to add fields from the the “invoice-info” table to your query, I kept the subquery (with IN instead of = as Mat already answered in the comment).

    query.prepare(QString("SELECT invoice FROM %1 WHERE invoice "
                          "IN (SELECT invoice FROM %2 WHERE user=:user)")
                  .arg(m_invoiceInfoTable, m_invoiceUserTable));    
    /*
    // Or with an inner join
    query.prepare(QString("SELECT %1.invoice FROM %1 "
                  "INNER JOIN %2 ON %1.invoice = %2.invoice "
                  "WHERE user=:user").arg(m_invoiceInfoTable, m_invoiceUserTable));*/    
    query.bindValue(":user", user);
    
    if (!query.exec()) { 
        tmp.append("Query error: %1" + query.lastError().text());
    } else if (!query.first()) { 
        tmp.append("No Unchecked invoice in the database");
    } else {
        do {
            tmp.append(query.value(0).toString());
        } while(query.next());
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used a join query for retrieving value from two tables one is
I want a linq query to return a calculated timespan, i have used the
I have a search form used to query service provisions, which I will call
I have a stored procedure that consists of a single select query used to
I need to used dynamic order query in mysql and i have successfully achieved
I have used traditional version control systems to maintain source code repositories on past
I have used IPC in Win32 code a while ago - critical sections, events,
I have used the XML Parser before, and even though it worked OK, I
We have a script used for each .item : $(.item).each(function(){ item_link = http://...; block
i have used this query to fetch the Record of the Datatable based 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.