Eventfilter crashes



  • i have an eventfilter event in the mainwindow.cpp. I also have an eventfilter event in the dialog but that is not working. i am wondering can the eventfilter work in two different placing because i am getting no errors but a crash when i try the eventfilter in the dialog.cpp. below is my code.

    dialog.h
    @private slots:
    bool eventFilter(QObject *object, QEvent *event);
    @

    dialog.cpp
    @dialog::dialog(QWidget *parent) :
    QDialog(parent, Qt::CustomizeWindowHint |
    Qt::WindowTitleHint ),
    ui(new Ui::dialog)
    {
    ui->setupUi(this);
    combobox->installEventFilter(this);
    }

    bool dialog::eventFilter(QObject *object, QEvent *event)
    {
    if (object == plainTextEdit && event->type() == QEvent::KeyPress)
    {
    QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
    if (keyEvent->key() == Qt::Key_Return)
    {
    // Special tab handling
    ui->sayButton->animateClick();
    on_sayButton_clicked();
    return true;
    }
    else
    {
    return dialog::eventFilter(object, event);
    }
    }
    else
    {
    return dialog::eventFilter(object, event);
    }
    }@



  • Of course it will crash.

    In line 24 and 29 you step into an infinite loop. You're calling the implementation of the eventFilter method of this class. You should call the base class' implementation:

    @
    return QDialog::eventFilter(object, event);
    @

    PS:
    eventFilter is not a slot! It's just an ordinary virtual public method.


Log in to reply
 

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