combo box text invading my other UI fields
-
Hi all -
Well, this one is rather interesting. Here's my UI:
and here's a screenshot of a debug session:
The variable s is supposed to be "Wifi Button" but is instead getting the value of the text from the time zone combo box. Sometimes it's not the Device Name field that gets corrupted; I've seen it happen to the MAC address and the serial number.Don't know what else to tell you...any ideas? I've cleaned and rebuilt, with the same results.
-
@jsulm I triple-checked that. Besides, it's not always the same field that gets corrupted.
Oddly enough, it appears to be somehow related to the model index I'm using. Just to experiment, I created a local copy for use in setting the correct value in the time zone combo box, and I haven't seen the error since.
-
@kshegunov it's not inside msg.init(), but I'm pretty sure you've identified the cause. I pass a pointer to the model into one of my QWidget objects, and I think it was altering the row/column settings. I still don't see how that would cause this error, but...who knows.
This is what I'd been doing:
row = m_qmi->row(); column = TAG_TIME_ZONE_CODE; m_qmi= m_modelDevice->getModel()->index(row, column); qv = m_modelDevice->getModel()->data(m_qmi); index = ui->comboBoxTimeZone->findData(qv); ui->comboBoxTimeZone->setCurrentIndex(index);
I've created a temporary variable to use instead:
row = m_qmi->row(); column = TAG_TIME_ZONE_CODE; qmiTemp = m_modelDevice->getModel()->index(row, column); qv = m_modelDevice->getModel()->data(qmiTemp); index = ui->comboBoxTimeZone->findData(qv); ui->comboBoxTimeZone->setCurrentIndex(index);
I haven't tested it exhaustively, but the problem hasn't recurred since this change.
-
If you need to store a
QModelIndex
then useQPersistentModelIndex
instead, that way changes to the model ordering/indices is going to be propagated. You should never keep an ordinary model index outside the current scope (i.e. stack frame). The point is that the model may (want to) reorder itself and your regular model index is going to just point to nirvana in this case.