Results 1 to 7 of 7

Thread: Retrieve userData of a comboBox item

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Retrieve userData of a comboBox item

    The manual says:

    Qt Code:
    1. void QComboBox::addItem ( const QString & text, const QVariant & userData = QVariant() )
    2. //Adds an item to the combobox with the given text, and containing the specified userData. The item is appended to the list of existing items.
    To copy to clipboard, switch view to plain text mode 

    but how can i get the userData of a given item?

    Bye
    Giuseppe CalÃ

  2. #2
    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: Retrieve userData of a comboBox item


  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Retrieve userData of a comboBox item

    I already tried it but returns text.

    Regards
    Giuseppe CalÃ

  4. #4
    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: Retrieve userData of a comboBox item

    And what/how did you add as user data? May we see the addItem() statement?
    J-P Nurmi

  5. #5
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Retrieve userData of a comboBox item

    sample code:

    Qt Code:
    1. QString bookTitle = "Beginning Joomla!";
    2. QString isbn13String = "978-1590598481";
    3. titleComboBox->addItem(bookTitle, isbn13String);
    To copy to clipboard, switch view to plain text mode 

    Thanks
    Giuseppe CalÃ

  6. #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: Retrieve userData of a comboBox item

    In this case use :
    Qt Code:
    1. QString data = titleComboBox->itemData(0).toString();
    To copy to clipboard, switch view to plain text mode 

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

    jiveaxe (23rd August 2007)

  8. #7
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Retrieve userData of a comboBox item

    Ok marcel, now works.

    Thank you
    Giuseppe CalÃ

Similar Threads

  1. Replies: 8
    Last Post: 15th May 2007, 09:21
  2. Can Qtable Item be a comboBox?
    By iGoo in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2006, 09:58

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.