Important: Please read the Qt Code of Conduct -

Can not debug my custom widget by using break point

  • I create a widget which was inherited from QComboBox, and I re-write the hidePopup() to let my widget would not hide popup when a item was clicked( to support multi select ).
    It works, but when I use break point to debug my program, if we get to the break point when my custom widget's popup was not hide, everything seems froze, I can not control anything with the popup always on the top. The only thing I can do is reboot my computer by long pressing my power key.
    I don't know what happened, but it seems the popup of my widget catch the keyboard focus(I guess)
    If I remove my re-write hidePopup(), the break point works well.
    Anyone can help me?

  • Qt Champions 2019

    @86926891 You app is simply paused as long as it is waiting at the breakpoint, just press F5 to continue from the break point...

  • @jsulm I know that, but F5, F10 & F11 do not works with the popup always on the top( even on the top of Qt Creator)

  • Qt Champions 2019

    @86926891 What are you doing in hidePopup()?

  • @jsulm This is how I re-write the hidePopup:
    void hidePopup()
    int width = this->width();
    int height = mListWidget->height();
    int x = QCursor::pos().x() - mapToGlobal(geometry().topLeft()).x() + geometry().x();
    int y = QCursor::pos().y() - mapToGlobal(geometry().topLeft()).y() + geometry().y();
    if (x >= 0 && x <= width && y >= this->height() && y <= height + this->height())
    // Item was clicked, do not hide popup

    The purpose of re-writing hidePopup() is to avoid the popup was hided when I click an item of my combobox

  • @jsulm So I get to my break point, the popup was not hid

  • @86926891
    I don't know your exact situation, but:

    • You are suppressing the fundamental ability to hide/dismiss the popup (when for whatever reason the if route of your code is followed). This may interfere with the basic working of a combobox, which might make things go nasty as you describe. Windows does a funny thing with the dropdown list of a combobox when it is displayed, making it a detached window which lies on top of everything; quite possibly it has grabbed keyboard focus too, basically Windows is waiting for that popup to disappear before anything else. Even native debuggers have a problem whereby if you hit a breakpoint when it is displayed you are stuck with the dropdown visible on top of everything else, which does not disappear till the popup gets closed, sometimes making debugging a bit awkward.

    • QComboBox/native combobox is an inherently single-select widget/control. Trying to make it multiselect sounds quite wrong to me. Use a QListWidget or something.

Log in to reply