I super appreciate if anyone can explain something I'm seeing with a combo box and my widget mapper when I call QInputDialog...

I have a QSqlTableModel with values from a row in the database mapped to a combo box. I have a second QsqlTableModel with values mapped to a combo box as well, and it's values are determined by using the first combo box selection as a filter. Image the first CB being a list of baseball teams and clicking on a team causes that team's players to populate this second one; choose a different team in the first and the 2nd changes accordingly.

This works perfectly until the user decides to add a new value to the 2nd combo box by clicking a "New" pushbutton -- I have a clicked() signal calling a slot which calls QInputDialog to prompt for a value...Suddenly, the value in my first combo box resets to the value found at current_index(0) as soon as the dialog is displayed! Just for fun, I checked the index of the first combo box and it's correct before the dialog is displayed, but reset afterwards...I can't find what I'm doing wrong so I don't know what I'm doing wrong...

I commented out the QInputDialog call and just hard coded a value and everything worked fine...

Any ideas? Thanks!


scott



This is the constructor for the first model/combo box
Qt Code:
  1. //*****************
  2. //* Rig Data... *
  3. //*****************
  4. rigmodel = new QSqlTableModel(this);
  5. rigmodel->setTable ("rig");
  6. rigmodel->sort (1, Qt::AscendingOrder);
  7. rigmodel->setEditStrategy (QSqlTableModel::OnFieldChange);
  8.  
  9. rigmodel->select ();
  10.  
  11. record = rigmodel->record (0);
  12. rig_id = record.value ("rig_id").toInt ();
  13.  
  14. rignamemapper = new QDataWidgetMapper(this);
  15. rignamemapper->setModel (rigmodel);
  16. rignamemapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
  17. rignamemapper->toFirst ();
  18. rignamemapper->addMapping (ui->RigInvNameCB, 1);
  19.  
  20. ui->RigInvNameCB->setModel (rigmodel);
  21. ui->RigInvNameCB->setModelColumn (1);
  22. ui->RigInvNameCB->setCurrentIndex (0);
To copy to clipboard, switch view to plain text mode 

This is for the second model/combo box
Qt Code:
  1. //***************************
  2. //* Rig Inventory Data... *
  3. //***************************
  4. riginvmodel = new QSqlTableModel(this);
  5. riginvmodel->setTable ("riginv");
  6. riginvmodel->sort (32, Qt::AscendingOrder);
  7. riginvmodel->setEditStrategy (QSqlTableModel::OnFieldChange);
  8. riginvmodel->setFilter (QString("riginv_rig_id = %1").arg(rig_id));
  9. riginvmodel->select ();
  10.  
  11. riginvmapper = new QDataWidgetMapper(this);
  12. riginvmapper->setModel (riginvmodel);
  13. riginvmapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
  14. riginvmapper->toFirst ();
  15. riginvmapper->addMapping (ui->EquipIDCB, 32);
  16.  
  17. ui->EquipIDCB->setModel (riginvmodel);
  18. ui->EquipIDCB->setModelColumn (32);
  19. ui->EquipIDCB->setCurrentIndex (0);
To copy to clipboard, switch view to plain text mode 


The slot where I'm having problems
Qt Code:
  1. void MainWindow::on_NewEquipIDPB_clicked()
  2. {
  3. int row;
  4. bool ok;
  5. int current_rig_id;
  6.  
  7. QString newequipname;
  8.  
  9. QSqlRecord record;
  10.  
  11. qDebug() << "combo index " << ui->RigInvNameCB->currentIndex ();
  12. qDebug() << "mapper index " << rignamemapper->currentIndex ();
  13.  
  14. //**************************************************
  15. //* Go get a name for this piece of equipment... *
  16. //**************************************************
  17. newequipname = QInputDialog::getText (this, tr("New Equipment Name"),
  18. tr("Enter a Name for this piece of Equipment"),
  19. QLineEdit::Normal, QString(), &ok);
  20.  
  21. qDebug() << "combo index " << ui->RigInvNameCB->currentIndex ();
  22. qDebug() << "mapper index " << rignamemapper->currentIndex ();
  23.  
  24. if (ok && !newequipname.isEmpty ())
  25. .
  26. .
  27. .
To copy to clipboard, switch view to plain text mode 

Results of the qDebug() calls:

Qt Code:
  1. combo index 2
  2. mapper index 2
  3.  
  4. combo index 0
  5. mapper index -1
To copy to clipboard, switch view to plain text mode