Hi,

i try to use a ComboBox for a selection of Baudrates.
I wan't to Display the Label for a Baudrate and store an unisigned int in the userData.

Here's my Code:
Qt Code:
  1. typedef struct
  2. {
  3. QString m_displayName;
  4. unsigned int m_Btr0Btr1;
  5. } baudrate_t;
  6.  
  7. ...
  8.  
  9. const baudrate_t available_bauds[]={ {"1 MBaud/s",0x014},
  10. {"800 kBaud/s",0x0016},
  11. {"500 kBaud/s",0x001C},
  12. {"250 kBaud/s",0x011C},
  13. {"125 kBaud/s",0x031C},
  14. {"100 kBaud/s",0x432F},
  15. {"95 kBaud/s",0xC34E},
  16. {"83 kBaud/s",0x852B},
  17. {"50 kBaud/s",0x472F},
  18. {"47 kBaud/s",0x1414},
  19. {"33 kBaud/s",0x8B2F},
  20. {"20 kBaud/s",0x532F},
  21. {"10 kBaud/s",0x672F},
  22. {"5 kBaud/s",0x7F7F},
  23. };
  24.  
  25. ...
  26.  
  27. for (int i = 0; i<( sizeof(available_bauds) / sizeof(available_bauds[0]) ); ++i)
  28. {
  29. QString Label = available_bauds[i].m_displayName;
  30. unsigned int BTR0BTR1 = available_bauds[i].m_Btr0Btr1;
  31. ui->cB_baudrate->addItem(Label,QVariant(BTR0BTR1));
  32. }
  33.  
  34. /*DEBUG Code*/
  35. qDebug() << ui->cB_baudrate->itemText(2);
  36. QVariant check_data = ui->cB_baudrate->itemData(2,Qt::UserRole);
  37. bool ok = false;
  38. unsigned int check_btr0btr1 = check_data.toUInt(&ok);
  39. if (ok)
  40. {
  41. qDebug() << check_btr0btr1;
  42. }
  43. /*END DEBUG CODE*/
To copy to clipboard, switch view to plain text mode 

the returned QVariant is always invalid.

What am i doing wrong?

OS Windows 7 64, QT 5.1.1, mingw48_32