Results 1 to 2 of 2

Thread: [Qt 4] QComboBox :: findData

  1. #1
    Join Date
    Jul 2006
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [Qt 4] QComboBox :: findData

    I have a problem with QCombo's findData function which is always returning -1 value.

    ---SerialPortPage.cpp---
    Qt Code:
    1. //I have declared metatype of custom StopBitsType.
    2. Q_DECLARE_METATYPE(StopBitsType)
    3.  
    4. ...
    5.  
    6. //then add some items to QComboBox
    7. stopCombo->addItem("1", qVariantFromValue(STOP_1));
    8. #ifdef _TTY_WIN_
    9. stopCombo->addItem("1.5", qVariantFromValue(STOP_1_5));
    10. #endif /*_TTY_WIN_*/
    11. stopCombo->addItem("2", qVariantFromValue(STOP_2));
    12.  
    13. ...
    14.  
    15. //this is working very well, returning value of proper StopBitsType
    16. stopCombo->itemData(stopCombo->currentIndex()).value<StopBitsType>()
    17.  
    18. ...
    19.  
    20. //however findData is always returning -1...
    21. stopCombo->findData(qVariantFromValue(STOP_2)) //printf or something
    To copy to clipboard, switch view to plain text mode 


    Am I doing something wrong :/ ? Have you ever use this function ?
    I didn't find any examples or information except short description in the documentation.

    int QComboBox::findData ( const QVariant & data, int role = Qt::UserRole, Qt::MatchFlags flags = Qt::MatchExactly | Qt::MatchCaseSensitive ) const
    Returns the index of the item containing the given data for the given role; otherwise returns -1.
    The flags specify how the items in the combobox are searched.
    The StopBitsType is defined as:


    ---qextserialbase.h---
    Qt Code:
    1. typedef enum _StopBitsType {
    2. STOP_1,
    3. STOP_1_5, //WINDOWS ONLY
    4. STOP_2
    5. } StopBitsType;
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt 4] QComboBox :: findData

    findData() works OK for me.

    The problem might be in Q_DECLARE_METATYPE --- IMO you can't use it for enums.

    qRegisterMetaType() docs say:
    Any class or struct that has a public constructor, a public copy constructor, and a public destructor can be registered.
    and Q_DECLARE_METATYPE uses qRegisterMetaType() internally.

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

    doc (12th July 2006)

Similar Threads

  1. QComboBox and item
    By drow in forum Qt Programming
    Replies: 4
    Last Post: 14th June 2006, 10:04
  2. Automatically add items to a QComboBox (Qt4)
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2006, 16:32
  3. QcomboBox items
    By therealjag in forum Newbie
    Replies: 5
    Last Post: 27th March 2006, 09:21
  4. QComboBox +SUSE10.0 +qt4.1 strange behavior
    By antonio.r.tome in forum Qt Programming
    Replies: 6
    Last Post: 20th March 2006, 18:49
  5. [QT3] QComboBox: Disable adding items on Enter-keypress
    By BrainB0ne in forum Qt Programming
    Replies: 7
    Last Post: 14th January 2006, 20:43

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.