Results 1 to 3 of 3

Thread: QListWidget string increment

  1. #1
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default QListWidget string increment

    Hello, i am trying to populate a QListWidget with the names Somename_1 to Somename_300.. But the problem is the names start with Somename_300 and decrement down to Somename_1 in the QListWidget.. How can i make it insert from Somename_1 and increment to Somename_300.
    Qt Code:
    1. for( int i=0 ; i<300; i++ )
    2. {
    3. listWidgetdata += QString("SOmename_%1").arg(i) + (i==299 ? "" : "");",");
    4. }
    5. for(int j=0; j < listWidgetdata.count();j++)
    6. {
    7. QListWidgetItem(item[kfast]->text());
    8. ParamsLW->insertItem(kfast,listWidgetdataat(j)); // kfast =0; at the start of the program
    9. ksast++;
    10. }
    To copy to clipboard, switch view to plain text mode 
    ParamsLW is the object name for the QListWidget.
    what is going wrong why is the counter starting the names from 300 instead of 1.

    thank you
    Last edited by nagabathula; 20th December 2010 at 07:45.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListWidget string increment

    Your code is not working. What about posting the real code? And the best way is a simple loop from 1 to 300 where you add an item at the end.

    Also what is item?

  3. The following user says thank you to Lykurg for this useful post:

    nagabathula (20th December 2010)

  4. #3
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: QListWidget string increment

    hello sir thank you i solved the problem.. it was a very silly mistake kfast was the item number but i incremented ksast i think thats why there was this error. I used the code from some previous post which i found on this forum to auto create incrementing names with numbers. This is what i did now.

    for( int i=0 ; i<300; i++ )
    {
    defineparameters.append(QString("Thermo Couple_%1").arg(i));
    }
    Qt Code:
    1. ParamsLW->insertItem(kfast,listWidgetdataat(j)); // kfast =0;
    2. ksast++; // supposed to be kfast++;
    To copy to clipboard, switch view to plain text mode 

    thank you sir problem is solved.
    Last edited by nagabathula; 20th December 2010 at 10:27.

Similar Threads

  1. Increment and Decrement Program
    By priya in forum Qt Programming
    Replies: 3
    Last Post: 3rd February 2010, 14:27
  2. QSqlQuery: Getting an Auto Increment value
    By Al_ in forum Qt Programming
    Replies: 3
    Last Post: 23rd December 2009, 23:15
  3. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 09:51
  4. Replies: 4
    Last Post: 9th May 2008, 18:02
  5. Custom spinner - fast increment/decrement
    By MrGarbage in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2007, 18:53

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.