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. QEvent
Forum Updated to NodeBB v4.3 + New Features

QEvent

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.3k Views 1 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.
  • Z Offline
    Z Offline
    zidom
    wrote on last edited by
    #1

    hi i am programming Qt in visual studio and i have a problem with this code
    myclass.h
    @#ifndef MYCLASS_H
    #define MYCLASS_H

    #include <QtGui/QMainWindow>
    #include "ui_myclass.h"

    class myclass : public QMainWindow
    {
    Q_OBJECT

    public:
    myclass(QWidget *parent = 0, Qt::WFlags flags = 0);
    ~myclass();

    private:
    Ui::MyClassClass ui;
    protected:
    bool eventFilter(QObject *, QEvent *);
    };

    #endif // myclass_H
    @
    myclass.cpp
    @#include "myclass.h"
    #include <QMouseEvent>
    #include <QMessageBox>
    myclass::myclass(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
    {
    ui.setupUi(this);
    ui.label->installEventFilter(this);
    }

    myclass::~myclass()
    {

    }

    bool myclass::eventFilter( QObject *target, QEvent *eve )
    {
    QMouseEvent *MouseEvent = static_cast < QMouseEvent *>( eve);
    if (MouseEvent->buttons()==Qt::LeftButton)
    {
    QMessageBox::information(this,"Click","");
    return true;
    }
    return myclass::eventFilter ( target , eve );
    }
    @

    my program breaks when it reach's to eventFilter
    !http://dl.2rialy.ir/ZiDoM-Ups/91/eror.JPG(error)!
    what should i do this code works in qtcreator but i want in visual studio

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      Infinite recursion in eventFilter function. You should call the base class version of the function if you want to inherit functionality in reimplemented virtual functions. Currently you're just doing recursion without break condition, of course leading to a stack overflow.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zidom
        wrote on last edited by
        #3

        can somebody explain more i need to make click event for label

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          what more?

          PS: You should be subclassing QLabel and reimplementing the according mouse events. Installing an event filter for that is hacky.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zidom
            wrote on last edited by
            #5

            i dont understand the reason and i want to know how should i make a click filter on label without creating new class

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DerManu
              wrote on last edited by
              #6

              In your "myclass::eventFilter ( target , eve );" function you call "myclass::eventFilter ( target , eve );" again (in the last line as return value). So you call the function itself again. And that calls itself again, and itself again, and itself again, and itself again,... stack overflow.

              You probably wanted to call "return [baseclass]::eventFilter ( target , eve );" where [baseclass] is the base class of the respective derived class. In this case QMainWindow.

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                zidom
                wrote on last edited by
                #7

                thank you very much i dont know why i did such a beginner mistake thanks

                1 Reply Last reply
                0

                • Login

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