Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate and report ComboBox bug to Qt #8

Open
guruofquality opened this issue Aug 19, 2014 · 0 comments
Open

duplicate and report ComboBox bug to Qt #8

guruofquality opened this issue Aug 19, 2014 · 0 comments
Assignees
Labels

Comments

@guruofquality
Copy link
Contributor


    /*!
     * 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);
    }
@guruofquality guruofquality self-assigned this Aug 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant