expected primary-expression before ‘*’ token



  • As I understand it, in c++ protected virtual member functions are designed to be overridden; however, I cannot get past the compile error. I believe that I have followed the rules exactly. What am I doing wrong?

    I get the following message when I try to execute a method of the base class, namely:

    expected primary-expression before ‘*’ token
    QTextEdit::keyPressEvent(QKeyEvent *e)
    ^

    header

    #include <QMainWindow>
    #include <QObject>
    #include <QWidget>
    #include <QTextEdit>
    #include <QKeyEvent>
    
    class FormulaEditor : public QTextEdit
    {
        Q_OBJECT
    public:
        explicit FormulaEditor(QWidget *parent = 0);
        void keyPressEvent(QKeyEvent * e) override ;
    };
    

    source

    #include "formulaeditor.h"
    #include <QDebug>
    #include <QKeyEvent>
    #include <QTextEdit>
    FormulaEditor::FormulaEditor(QWidget *parent) : QTextEdit(parent){}
    
    
    void FormulaEditor::keyPressEvent(QKeyEvent *e)
    {
        qDebug() << "Key Press Event " << e;
        if (e->key() == Qt::Key_ParenLeft) {
                qDebug() << "Left Parenthesis";
        }
        QTextEdit::keyPressEvent(QKeyEvent *e);
        e->ignore();
    }
    

    (Chris Kawa) Edit: added code formatting tags


  • Moderators

    When calling a function you shouldn't specify the argument types again:

    void FormulaEditor::keyPressEvent(QKeyEvent *e)
    {
        ...
        QTextEdit::keyPressEvent(QKeyEvent *e);  // <-- here's the problem
        e->ignore();
    }
    

    Should be:

    void FormulaEditor::keyPressEvent(QKeyEvent *e)
    {
        ...
        QTextEdit::keyPressEvent(e);
        e->ignore();
    }
    


  • @Chris-Kawa

    I know. A very stupid mistake:

    QTextEdit::keyPressEvent(QKeyEvent *e); is a prototype definition, while

    QTextEdit::keyPressEvent(e); calls the function for execution.

    When I discovered what I had done I marked this post as solved to cover up my stupidity, then thoroughly chastised myself.


  • Moderators

    No worries. Happens sometimes.


Log in to reply
 

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