Results 1 to 7 of 7

Thread: problem with "QListWidget" item

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default problem with "QListWidget" item

    I have a QListWidget "lwlistData" and I want the text of the third item in the list . (n = 3);

    I assume I should use
    QListWidgetItem * QListWidget::item ( int row ) const

    Returns the item that occupies the given row in the list if one has been set; otherwise returns 0.
    when I use
    Qt Code:
    1. QString t = lwDataList->item(n - 1);
    To copy to clipboard, switch view to plain text mode 
    I get
    dlgmain.cpp:1067: error: invalid conversion from 'QListWidgetItem*' to 'char'
    dlgmain.cpp:1067: error: initializing argument 1 of 'QString& QString:perator=(char)'
    Please show what the command should be.

    I have been using Qt3 and now Ot4 since it came out and I still have MAJOR trouble deciphering this stuff. I go to "more" and there is all kind of help for inserting items, but none that I can find on getting an item.

    If for each command there was a simple example of it's use as there is on some of the commands, it would be wonderful for "stupid" people like me.
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: problem with "QListWidget" item

    The docs say it all - just make sure you read correctly
    QListWidgetItem * QListWidget::item ( int row ) const
    1.
    QString t = lwDataList->item(n - 1);
    got it?

    try
    Qt Code:
    1. QString t = lwDataList->item(n - 1)->text();
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with "QListWidget" item

    Qt Code:
    1. QString t = lwDataList->item(n - 1)->text();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2007
    Posts
    81
    Thanks
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with "QListWidget" item

    damnit, these two beat me to it :P

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: problem with "QListWidget" item

    Use QListWidgetItem::text() to get the text of the item:
    Qt Code:
    1. QString t = lwDataList->item(n - 1)->text();
    2. // or more in a more safe way
    3. QListWidgetItem* item = lwDataList->item(n - 1);
    4. if (item) t = item->text();
    To copy to clipboard, switch view to plain text mode 

    Edit: Damn, I'm slow today
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    impeteperry (16th April 2007)

  7. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with "QListWidget" item

    Ok, give us our thanks now...

  8. The following user says thank you to marcel for this useful post:

    impeteperry (16th April 2007)

  9. #7
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: problem with "QListWidget" item

    Quote Originally Posted by marcel View Post
    Ok, give us our thanks now...
    I certainly to

Similar Threads

  1. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 15:36
  2. problem withh QListViewItemIterator
    By :db:sStrong in forum Qt Programming
    Replies: 10
    Last Post: 7th March 2007, 15:05
  3. Higlighting wrong item
    By Kapil in forum Qt Programming
    Replies: 5
    Last Post: 21st April 2006, 16:08
  4. Replies: 16
    Last Post: 7th March 2006, 16:57
  5. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 02:34

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.