High CPU Usage for Combo Box



  • Hello,

    looking at the following example,

    @class BoxPopupMenu : public QComboBox
    {

    public:
    BoxPopupMenu(QWidget *parent = 0) :
    QComboBox(parent)
    {
    view()->installEventFilter(this);
    };

    private:
    bool eventFilter(QObject *t, QEvent *e)
    {
    return true;
    }
    };@

    I have seen that eventFilter function intensifies my CPU usage to 50%.
    Inside this function I have written:

    @ QKeyEvent keyEvent = static_cast<QKeyEvent>(e);
    int key = keyEvent->key();

        if(e->type() == QEvent::KeyPress)
        {
            switch(key)
            {
                 ...
            }
        }@
    

    The problem persists in both the examples.
    Do you know what could be the problem?

    Luca



  • When eventFilter returns true it "stops processing":http://qt-project.org/doc/qt-5/eventsandfilters.html#event-filters of the events. But the events continue to come so an empty eventFilter takes all CPU.
    You need to return false from eventFilter to let Qt to process the events which are not interesting for your eventFilter.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.