pothosware / PothosWidgets

Graphical widgets to supplement the Pothos GUI
https://github.com/pothosware/PothosWidgets/wiki
Boost Software License 1.0
6 stars 6 forks source link

duplicate and report ComboBox bug to Qt #8

Open guruofquality opened 10 years ago

guruofquality commented 10 years ago

    /*!
     * FIXME -- This is almost certainly a Qt bug-workaround.
     * Changing this widget's parent causes a segfault in QComboBox.
     * Start with no parent, set parent, clear parent, set again -> segfault.
     * The workaround is to create a new QComboBox and restore its state.
     */
    bool event(QEvent *e)
    {
        if (e->type() == QEvent::ParentAboutToChange)
        {
            const auto oldIndex = _comboBox->currentIndex();
            QStringList oldItems; for (int i = 0; i < _comboBox->count(); i++) oldItems.push_back(_comboBox->itemText(i));
            delete _comboBox;
            _comboBox = (new QComboBox(this));
            layout()->addWidget(_comboBox);
            _comboBox->addItems(oldItems);
            _comboBox->setCurrentIndex(oldIndex);
        }
        return QWidget::event(e);
    }