Results 1 to 5 of 5

Thread: QListWidget difficulty getting item text and iterating

  1. #1
    Join Date
    Aug 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb QListWidget difficulty getting item text and iterating

    Hello,

    Im newbie, and I wish somebody helps me getting the text value of a Row in a QListWidget named list_result, sum it with the other values and then display on an Edit.

    I need to iterate it so i can sum all the numbers in the list, but i dont know how to get the TEXT out of it... Also, I think I need to turn the text into a float type to calculate, but i can't get it working, tried many combinations of codes.... Somebody help me please


    Qt Code:
    1. float sum = 0;
    2. float sum2 = 0;
    3.  
    4.  
    5. //do the loop thing
    6. for (int = 0; i<list_result->count(); i++) {
    7.  
    8. //get the text from each row of the QListWidget, and transform to Float (?)
    9. sum2 = ???
    10.  
    11. //sum the numbers
    12. sum = sum + sum2;
    13.  
    14. }
    15.  
    16. //show the result in an Edit by transforming into a String
    17. ed_result->setText(QString::number(sum));
    To copy to clipboard, switch view to plain text mode 



    Edit: Qt version 4.6.2

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget difficulty getting item text and iterating


  3. #3
    Join Date
    Aug 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListWidget difficulty getting item text and iterating

    have read that many times, but the usage of it is not clear to me...

  4. #4
    Join Date
    Aug 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListWidget difficulty getting item text and iterating

    if i use like

    Qt Code:
    1. sum2 = list_result->item(i).toFloat();
    To copy to clipboard, switch view to plain text mode 

    i get this error:

    error: request for member 'to Float' in .......item(i) which is of non-class type 'QListWidgetItem'

  5. #5
    Join Date
    Aug 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListWidget difficulty getting item text and iterating

    ooohhh yeahhh i got it

    its:

    Qt Code:
    1. sum2 = list_result->item(i)->text().toFloat();
    To copy to clipboard, switch view to plain text mode 

    god!

    Thanks for the help.

Similar Threads

  1. difficulty in conversion
    By mohanakrishnan in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2009, 10:31
  2. QListWidget Item
    By csvivek in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2008, 09:02
  3. remove item from QListWidget
    By yushinee in forum Newbie
    Replies: 3
    Last Post: 2nd October 2007, 20:40
  4. Reg - add item in QListWidget
    By suresh in forum Newbie
    Replies: 1
    Last Post: 1st September 2006, 17:52
  5. extract item from QListWidget
    By impeteperry in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 19:41

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.