connect function fails because the signal cannot find the object

62 Views Asked by At

When calling QObject::connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type = Qt::AutoConnection), I get the error "cannot call a member funtion without object*".

I'm trying to connect a signal emit by a custom button to a slot defined in the container class of the button. In the container i define:


    signals:
        void hovered();

In the container header, I define an object of customButton class:

customButton* casilla = new customButton;

And the slot like:

    public slots:
        void mostrarCasilla();

Now, in the container constructor, I try to connect the signal and the slot with this line

QObject::connect(casilla,&customButton::hovered(),this,&board::mostrarCasilla());

I think is some kind of simple mistake, I'll put the full code to give an example for the community if I make it work

1

There are 1 best solutions below

2
0xlitf On

&A::func is a member function pointer, the role of & is fetch the address of func.

for func(), () is a function call, perhaps you can get a value after func(), but this value is r-value, & need a l-value, so &A::func() is wrong in any situation.