Results 1 to 2 of 2

Thread: QDataWidgetMapper/QInputDialog oddities...

  1. #1
    Join Date
    Jan 2011
    Location
    Richmond, VA
    Posts
    94
    Thanks
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QDataWidgetMapper/QInputDialog oddities...

    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 

  2. #2
    Join Date
    Jan 2011
    Location
    Richmond, VA
    Posts
    94
    Thanks
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QDataWidgetMapper/QInputDialog oddities...

    And it gets stranger:

    1) This issue also happens when my "delete" and "copy" slots are fired as well as clicking in a line edit on my form...
    2) This problem only happens once! When it does if I re-select from my first CB it never happens again; I can reselect any value from my first CB and then when I click any other widget it works perfect.
    3) I have a slot connected to the first CB this is *not* fired when I'm seeing the value reset itself -- I thought that may be happening but it's not, so somewhere an index is being reset/mapper is losing connection to the CB when another widget is clicked, but again, only once...


    scott
    Last edited by scott_hollen; 26th September 2011 at 03:36.

Similar Threads

  1. Replies: 4
    Last Post: 29th March 2019, 14:58
  2. QInputDialog and OSG
    By Pertur in forum Qt Programming
    Replies: 3
    Last Post: 30th July 2010, 09:34
  3. How to use Qinputdialog in Symbian
    By ramesh.bs in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 2nd June 2010, 11:51
  4. QInputDialog default value
    By dbrmik in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2009, 16:07
  5. QInputDialog
    By bkv in forum Newbie
    Replies: 2
    Last Post: 6th October 2006, 07:34

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.