Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. expected primary-expression before ‘*’ token
QtWS25 Last Chance

expected primary-expression before ‘*’ token

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 5.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ofmrew
    wrote on 3 May 2017, 19:01 last edited by Chris Kawa 5 May 2017, 17:50
    #1

    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 5 May 2017, 17:48 last edited by
      #2

      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();
      }
      
      O 1 Reply Last reply 5 May 2017, 18:41
      1
      • C Chris Kawa
        5 May 2017, 17:48

        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();
        }
        
        O Offline
        O Offline
        ofmrew
        wrote on 5 May 2017, 18:41 last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 5 May 2017, 19:13 last edited by
          #4

          No worries. Happens sometimes.

          1 Reply Last reply
          0

          1/4

          3 May 2017, 19:01

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved