Results 1 to 4 of 4

Thread: How to extract all datas from a column of a table and add those?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2019
    Posts
    6
    Thanks
    1
    Qt products
    Qt5

    Default How to extract all datas from a column of a table and add those?

    I tried to extract data from Amount column of my table and add all those and save them to string. But only first row is extracted,could anyone help?

    Here is my codes:
    Qt Code:
    1. QList<QString> Dbase_Cashier::getAmount()
    2. {
    3. QList<QString> amountdetails;
    4. QSqlQuery qry;
    5. qry.prepare(QString("SELECT Amount FROM Bill"));
    6. if(!qry.exec())
    7. {
    8. qDebug()<<"Error in retriving data"<<qry.lastError();
    9. }
    10. else
    11. {
    12.  
    13. if(qry.next())
    14. {
    15. QString i=qry.value(0).toString();
    16. amountdetails.push_front(i);
    17.  
    18. }
    19. else
    20. {
    21. qDebug()<<"not executing qyery";
    22. }
    23.  
    24. }
    25. qDebug()<<amountdetails.count();
    26. return amountdetails;
    27. }
    To copy to clipboard, switch view to plain text mode 
    And I have called above function as follows:
    Qt Code:
    1. void CashierWindow::showAmount()
    2. {
    3. Dbase_Cashier db("SBS.db");
    4. QList<QString> amountdetails=db.getAmount();
    5.  
    6. if(amountdetails.isEmpty())
    7. {
    8. qDebug()<<"empty";
    9. }
    10. else
    11. {
    12. qDebug()<<amountdetails.count();
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    Here,I got the console output as 1.
    Last edited by anda_skoa; 14th July 2019 at 07:51. Reason: missing [code] tags

Similar Threads

  1. Column/Row no of ComboBox Widget in Table
    By ankurjain in forum Qt Programming
    Replies: 13
    Last Post: 6th December 2011, 11:03
  2. how to add a image to table column header
    By nageshvk in forum Newbie
    Replies: 3
    Last Post: 25th December 2010, 13:34
  3. Listing a column of a table to a QListWidget
    By Luc4 in forum Qt Programming
    Replies: 1
    Last Post: 2nd October 2010, 20:21
  4. Replies: 2
    Last Post: 5th September 2010, 14:06
  5. Table Column Problem
    By kenny_isles in forum Newbie
    Replies: 1
    Last Post: 5th March 2007, 23:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.