Hi, i'm subclasing a QComboBox class and trying to use the itemData() to store the ID of the table from the database using this code:
Qt Code:
  1. void ECBClientes::inicializar()
  2. {
  3. // Cargo los datos del modelo
  4. QSqlQuery cola;
  5. if( cola.exec( "SELECT id, razon_social FROM clientes ORDER BY razon_social ASC" ) ) {
  6. int pos = 0;
  7. while( cola.next() ) {
  8. this->insertItem( pos, cola.record().value(1).toString() );
  9. this->setItemData( pos , cola.record().value(0), Qt::UserRole );
  10. if( this->itemData( pos, Qt::UserRole ).isValid() )
  11. qDebug( this->itemData( pos, Qt::UserRole ).toString().toLocal8Bit() );
  12. pos++;
  13. }
  14. if( pos == 0 ) {
  15. qWarning( "No hay ningun cliente para cargar!" );
  16. this->lineEdit()->setText( "No hay clientes cargados..." );
  17. }
  18. this->setEnabled( true );
  19. this->setCurrentIndex( -1 );
  20. } else {
  21. qWarning( "Error al intentar ejecutar la cola para cargar los clientes" );
  22. qDebug( cola.lastError().text().toLocal8Bit() );
  23. qDebug( cola.lastQuery().toLocal8Bit() );
  24. }
  25. }
To copy to clipboard, switch view to plain text mode 

but if( this->itemData( pos, Qt::UserRole ).isValid() ) never returns true so no data is stored in the model?
Anyone have the same issue?

Qt 4.7 tested on Linux slackware and debian in two different machines with the same result.