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. Try to emit signal in keyPressEvent
Qt 6.11 is out! See what's new in the release blog

Try to emit signal in keyPressEvent

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 425 Views 2 Watching
  • 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.
  • Evgeny SiberiaE Offline
    Evgeny SiberiaE Offline
    Evgeny Siberia
    wrote on last edited by Evgeny Siberia
    #1

    Hi. Why do I have errors? What is my mistake?
    The first in constructor: undefined reference to `vtable for LineEditClickedButton;
    And others in keyPressEvent: undefined reference to LineEditClickedButton::buttonPressed

    #include <QLineEdit>
    
    class LineEditClickedButton : public QLineEdit
    {
        Q_OBJECT
    public:
        explicit LineEditClickedButton(QWidget *parent = nullptr);
    
    protected:
        void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
    
    signals:
        void buttonPressed(QString button);
    };
    
    #include "lineeditclickedbutton.h"
    #include <QKeyEvent>
    
    LineEditClickedButton::LineEditClickedButton(QWidget *parent) :
        QLineEdit(parent)
    {}
    
    void LineEditClickedButton::keyPressEvent(QKeyEvent *e)
    {
        switch (e->key()) {
        case Qt::Key_Escape:
            emit buttonPressed("esc");
            break;
        case Qt::Key_Tab:
            emit buttonPressed("tab");
            break;
        }
        QLineEdit::keyPressEvent(e);
    }
    

    if you see mistakes in English tell me about it

    JonBJ kshegunovK 2 Replies Last reply
    0
    • Evgeny SiberiaE Evgeny Siberia

      Hi. Why do I have errors? What is my mistake?
      The first in constructor: undefined reference to `vtable for LineEditClickedButton;
      And others in keyPressEvent: undefined reference to LineEditClickedButton::buttonPressed

      #include <QLineEdit>
      
      class LineEditClickedButton : public QLineEdit
      {
          Q_OBJECT
      public:
          explicit LineEditClickedButton(QWidget *parent = nullptr);
      
      protected:
          void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
      
      signals:
          void buttonPressed(QString button);
      };
      
      #include "lineeditclickedbutton.h"
      #include <QKeyEvent>
      
      LineEditClickedButton::LineEditClickedButton(QWidget *parent) :
          QLineEdit(parent)
      {}
      
      void LineEditClickedButton::keyPressEvent(QKeyEvent *e)
      {
          switch (e->key()) {
          case Qt::Key_Escape:
              emit buttonPressed("esc");
              break;
          case Qt::Key_Tab:
              emit buttonPressed("tab");
              break;
          }
          QLineEdit::keyPressEvent(e);
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Evgeny-Siberia
      Since I can't spot anything: have you cleaned out all intermeditae files in the compilation output directory and rebuilt? Especially if you have recently added the Q_OBJECT. At least make sure the error remains.

      1 Reply Last reply
      3
      • Evgeny SiberiaE Evgeny Siberia

        Hi. Why do I have errors? What is my mistake?
        The first in constructor: undefined reference to `vtable for LineEditClickedButton;
        And others in keyPressEvent: undefined reference to LineEditClickedButton::buttonPressed

        #include <QLineEdit>
        
        class LineEditClickedButton : public QLineEdit
        {
            Q_OBJECT
        public:
            explicit LineEditClickedButton(QWidget *parent = nullptr);
        
        protected:
            void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
        
        signals:
            void buttonPressed(QString button);
        };
        
        #include "lineeditclickedbutton.h"
        #include <QKeyEvent>
        
        LineEditClickedButton::LineEditClickedButton(QWidget *parent) :
            QLineEdit(parent)
        {}
        
        void LineEditClickedButton::keyPressEvent(QKeyEvent *e)
        {
            switch (e->key()) {
            case Qt::Key_Escape:
                emit buttonPressed("esc");
                break;
            case Qt::Key_Tab:
                emit buttonPressed("tab");
                break;
            }
            QLineEdit::keyPressEvent(e);
        }
        
        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        Besides what @JonB said, is this in a library?

        Also a piece of advice stick to const <Type> & for signal types.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        1

        • Login

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