Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

combo box text invading my other UI fields



  • Hi all -

    Well, this one is rather interesting. Here's my UI:
    ui.PNG
    and here's a screenshot of a debug session:
    creator.PNG
    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.


  • Lifetime Qt Champion

    @mzimmers Are you sure you named the widgets correctly? I mean, is ui->deviceName really the widget for device name and not time zone?



  • @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.



  • Yeah, my advice would have been to rerun uic, looks like something got drunk in there


  • Qt Champions 2017

    Mind showing us msg.init()?
    If you're keeping a QModelIndex() somewhere it may (and sometimes will) get invalidated after a submit() (whatever model it is).



  • @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.


  • Qt Champions 2017

    If you need to store a QModelIndex then use QPersistentModelIndex 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.


Log in to reply