简体   繁体   English

QT没有匹配功能连接到

[英]QT connect no matching function to call to

Hey guys 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 tried it with >>all<< my classes inheriting from QObject but it showed the same error. 我已经尝试在单独的类中进行连接,我尝试使用旧的连接语法(SIGNAL / SLOT(function)),并尝试使用>> all <<我的类继承自QObject,但它显示了相同的错误。 Also it says something that the function expects 3 arguments but gets 4. and seems to point at the connect(...renderField). 它还表示该函数需要3个参数但得到4个参数,并且似乎指向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. 我听说可以在MainWindow类中完成所有这些操作的解决方案,但这对我来说不是一个选择。

You have to pass the instance pointer: 您必须传递实例指针:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM