Search code examples
c++functionqtqobjectqt-connection

QT connect no matching function to call to


I know there are already some threads for this question but I think I made none of the mistakes others did which led to the problem. So here is my code:

#include "consolerender.h"

consoleRender::consoleRender(QObject *parent) :
    QObject(parent) {
    connect(Enviroment::instance, &Enviroment::enviromentChanged,
            this, &consoleRender::renderField);
}

And the header:

class consoleRender : public QObject
{
    Q_OBJECT

public:
    explicit consoleRender(QObject *parent = 0);

public slots:
    void renderField();

};

And the Enviroment.h

class Enviroment : public QObject
{
    Q_OBJECT

public:

    static Enviroment& instance();
    virtual ~Enviroment();

//stuff...

signals:
    void enviromentChanged();

I already tried to do the connect in a separate class. I tried to use the old connect syntax (SIGNAL/SLOT(function)) and I tried it with >>all<< my classes inheriting from QObject but it showed the same error. Also it says something that the function expects 3 arguments but gets 4. It seems to point at the connect(...renderField). I heard of a solution to just do all of that in the MainWindow class but that is not an option for me.


Solution

  • You have to pass the instance pointer:

    connect(&Enviroment::instance(), &Enviroment::enviromentChanged,
            this, &consoleRender::renderField);