Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Send singal in eventFilter
Forum Updated to NodeBB v4.3 + New Features

Send singal in eventFilter

Scheduled Pinned Locked Moved Solved QML and Qt Quick
12 Posts 3 Posters 1.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.
  • K Offline
    K Offline
    Knj.Tkm
    wrote on last edited by
    #1

    Hi.
    I want to send signal in eventFilter,but it fail.
    Can't send signal in eventFilter?

    Event.cpp

    bool Event::eventFilter(QObject *, QEvent *ev)
    {
        if( ev->type() == QEvent::Enter ){
            qDebug() << "ENTER!";
            emit sigMouse();
            return true;
        }
        if( ev->type() == QEvent::Leave){
            qDebug() << "LEAVE!";
            emit sigMouse();
            return true;
        }
        return false;
    }
    

    Connect.cpp

    Connect::Connect(QObject *parent) : QObject(parent)
    {
        connect( &eve, SIGNAL( sigMouse() ), this, SLOT(slotMouse() ));
    }
    
    void Connect::slotMouse()
    {
        qDebug() << "HERE";
    }
    

    It show "ENTER!" and "LEAVE!", but "HERE” is can't show.

    jsulmJ 1 Reply Last reply
    0
    • K Knj.Tkm

      @J-Hilk
      Sorry, I was wrong.

      MyWidget.h

      namespace Ui {
      class MyWidget;
      }
      
      class MyWidget: public QWidget
      {
          Q_OBJECT
      
      public:
          MyWidget();
      
      private:
      
          QVBoxLayout* myMainLayout;
          Ui::Chart* myWidget;
      
          Event event;
      };
      

      MyWidget.cpp

      MyWidget::MyWidget() : QWidget(), myWidget(new Ui::MyWidget)
      {
          myWidget->setupUi(this);
          myMainLayout = new QVBoxLayout;
          myMainLayout->setMargin(0);
          myWidget->frame->setLayout(myMainLayout);
          myWidget->frame->setGeometry(0, 0, 1360, 760);
          myWidget->rectangle->installEventFilter(&event);
      }
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #10

      @Knj-Tkm well, there's your problem,

      you have 2 Event instances, one in MyWidget and one in Connect,

      that in MyWidget is installed, and emits the debug texts, that one in Connect is not, but you connect to those signals.

      You expect citrus smell from an apple :D
      Fix that


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      K jsulmJ 2 Replies Last reply
      1
      • K Knj.Tkm

        Hi.
        I want to send signal in eventFilter,but it fail.
        Can't send signal in eventFilter?

        Event.cpp

        bool Event::eventFilter(QObject *, QEvent *ev)
        {
            if( ev->type() == QEvent::Enter ){
                qDebug() << "ENTER!";
                emit sigMouse();
                return true;
            }
            if( ev->type() == QEvent::Leave){
                qDebug() << "LEAVE!";
                emit sigMouse();
                return true;
            }
            return false;
        }
        

        Connect.cpp

        Connect::Connect(QObject *parent) : QObject(parent)
        {
            connect( &eve, SIGNAL( sigMouse() ), this, SLOT(slotMouse() ));
        }
        
        void Connect::slotMouse()
        {
            qDebug() << "HERE";
        }
        

        It show "ENTER!" and "LEAVE!", but "HERE” is can't show.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Knj-Tkm Please check whether your connect() call succeeded (it returns a bool). Even better is to use new Qt5 connect syntax.
        Also, it is not clear what eve is and whether it is the one which actually used.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        K 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Knj-Tkm Please check whether your connect() call succeeded (it returns a bool). Even better is to use new Qt5 connect syntax.
          Also, it is not clear what eve is and whether it is the one which actually used.

          K Offline
          K Offline
          Knj.Tkm
          wrote on last edited by
          #3

          @jsulm
          connect is true.
          eve is create an object in Header

          private :
               Event eve;
          
          jsulmJ 1 Reply Last reply
          0
          • K Knj.Tkm

            @jsulm
            connect is true.
            eve is create an object in Header

            private :
                 Event eve;
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @Knj-Tkm said in Send singal in eventFilter:

            eve is create an object in Header

            And is this eve really the one which is used and gets the events? Do you have another one somewhere?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            K 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Knj-Tkm said in Send singal in eventFilter:

              eve is create an object in Header

              And is this eve really the one which is used and gets the events? Do you have another one somewhere?

              K Offline
              K Offline
              Knj.Tkm
              wrote on last edited by
              #5

              @jsulm
              Yes, It using.
              I don't have another.

              J.HilkJ 1 Reply Last reply
              0
              • K Knj.Tkm

                @jsulm
                Yes, It using.
                I don't have another.

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #6

                @Knj-Tkm this

                Connect::Connect(QObject *parent) : QObject(parent)
                {
                    connect( &eve, SIGNAL( sigMouse() ), this, SLOT(slotMouse() ));
                }
                

                looks like the constructor, where I would have expected to see the event filter applied to the class, where do you apply it ?


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                K 1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @Knj-Tkm this

                  Connect::Connect(QObject *parent) : QObject(parent)
                  {
                      connect( &eve, SIGNAL( sigMouse() ), this, SLOT(slotMouse() ));
                  }
                  

                  looks like the constructor, where I would have expected to see the event filter applied to the class, where do you apply it ?

                  K Offline
                  K Offline
                  Knj.Tkm
                  wrote on last edited by
                  #7

                  @J-Hilk
                  In Header

                  #include <QObject>
                  #include "Event.h"
                  
                  class Connect: public QObject
                  {
                      Q_OBJECT
                  
                  public:
                      Connect(QObject *parent = nullptr);
                  
                  public slots:
                  
                      void slotMouse(void);
                  
                  private:
                      Event eve;
                  };
                  
                  J.HilkJ 1 Reply Last reply
                  0
                  • K Knj.Tkm

                    @J-Hilk
                    In Header

                    #include <QObject>
                    #include "Event.h"
                    
                    class Connect: public QObject
                    {
                        Q_OBJECT
                    
                    public:
                        Connect(QObject *parent = nullptr);
                    
                    public slots:
                    
                        void slotMouse(void);
                    
                    private:
                        Event eve;
                    };
                    
                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #8

                    @Knj-Tkm
                    so, you're missing the installEventFilter call?


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    K 1 Reply Last reply
                    0
                    • J.HilkJ J.Hilk

                      @Knj-Tkm
                      so, you're missing the installEventFilter call?

                      K Offline
                      K Offline
                      Knj.Tkm
                      wrote on last edited by Knj.Tkm
                      #9

                      @J-Hilk
                      Sorry, I was wrong.

                      MyWidget.h

                      namespace Ui {
                      class MyWidget;
                      }
                      
                      class MyWidget: public QWidget
                      {
                          Q_OBJECT
                      
                      public:
                          MyWidget();
                      
                      private:
                      
                          QVBoxLayout* myMainLayout;
                          Ui::Chart* myWidget;
                      
                          Event event;
                      };
                      

                      MyWidget.cpp

                      MyWidget::MyWidget() : QWidget(), myWidget(new Ui::MyWidget)
                      {
                          myWidget->setupUi(this);
                          myMainLayout = new QVBoxLayout;
                          myMainLayout->setMargin(0);
                          myWidget->frame->setLayout(myMainLayout);
                          myWidget->frame->setGeometry(0, 0, 1360, 760);
                          myWidget->rectangle->installEventFilter(&event);
                      }
                      
                      J.HilkJ 1 Reply Last reply
                      0
                      • K Knj.Tkm

                        @J-Hilk
                        Sorry, I was wrong.

                        MyWidget.h

                        namespace Ui {
                        class MyWidget;
                        }
                        
                        class MyWidget: public QWidget
                        {
                            Q_OBJECT
                        
                        public:
                            MyWidget();
                        
                        private:
                        
                            QVBoxLayout* myMainLayout;
                            Ui::Chart* myWidget;
                        
                            Event event;
                        };
                        

                        MyWidget.cpp

                        MyWidget::MyWidget() : QWidget(), myWidget(new Ui::MyWidget)
                        {
                            myWidget->setupUi(this);
                            myMainLayout = new QVBoxLayout;
                            myMainLayout->setMargin(0);
                            myWidget->frame->setLayout(myMainLayout);
                            myWidget->frame->setGeometry(0, 0, 1360, 760);
                            myWidget->rectangle->installEventFilter(&event);
                        }
                        
                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #10

                        @Knj-Tkm well, there's your problem,

                        you have 2 Event instances, one in MyWidget and one in Connect,

                        that in MyWidget is installed, and emits the debug texts, that one in Connect is not, but you connect to those signals.

                        You expect citrus smell from an apple :D
                        Fix that


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        K jsulmJ 2 Replies Last reply
                        1
                        • J.HilkJ J.Hilk

                          @Knj-Tkm well, there's your problem,

                          you have 2 Event instances, one in MyWidget and one in Connect,

                          that in MyWidget is installed, and emits the debug texts, that one in Connect is not, but you connect to those signals.

                          You expect citrus smell from an apple :D
                          Fix that

                          K Offline
                          K Offline
                          Knj.Tkm
                          wrote on last edited by Knj.Tkm
                          #11

                          @J-Hilk
                          I understand the principle, but I don't know how to do it.
                          What should I do?

                          Ok, I totally get it now.
                          You were trying to use it in a different place than where you installed it...
                          Thanks!

                          1 Reply Last reply
                          1
                          • J.HilkJ J.Hilk

                            @Knj-Tkm well, there's your problem,

                            you have 2 Event instances, one in MyWidget and one in Connect,

                            that in MyWidget is installed, and emits the debug texts, that one in Connect is not, but you connect to those signals.

                            You expect citrus smell from an apple :D
                            Fix that

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #12

                            @Knj-Tkm @J-Hilk said in Send singal in eventFilter:

                            you have 2 Event instances, one in MyWidget and one in Connect

                            So, my assumption was correct...

                            https://forum.qt.io/topic/113070/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