一旦添加了信号/插槽,简单的Qt App就会拒绝编译

rja*_*cks 5 qt compiler-errors signals-slots

所以基本上,我正在制作一个非常简单的Qt应用程序来帮助我学习OpenGL.
我的想法是我有两个窗口,一个是GL上下文(GLWidget,派生自QGLWidget),另一个是带有几个进度条和文本区域的简单GUI.

我可以让应用程序编译和运行,一切都很美丽直到我试图连接两个窗口之间的信号和插槽.我已经阅读了关于QGLWidget的文档,关于信号和插槽的官方教程,以及文档int connect().

为了说明:我的main.cpp文件:

#include <QApplication>
#include <QObject>

#include "glwidget.h"
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    MainWindow *mWindow = new MainWindow();
    GLWidget *gl = new GLWidget();

    //If this line is commented out, the program compiles and runs
    connect(gl, SIGNAL(fpsReport(float)), mWindow, SLOT(updateFPS(float));

    mWindow->show();
    gl->show();

    return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

我得到的具体编译器错误是:

In function 'int qMain(int, char**)':
invalid conversion from 'GLWidget*' to 'SOCKET'
cannot convert 'const char*' to 'const sockaddr*' for argument '2' to 'int
connect(SOCKET, const sockaddr*, int)'

不确定这是否相关,但我使用Qt Creator 2.0.1,基于Qt 4.7.0(32位).运行32位Windows 7旗舰版.

Fre*_*red 10

connect是QObject的静态成员.在QObject上下文之外使用时,您需要指定范围:

QObject::connect(gl, SIGNAL(fpsReport(float)), mWindow, SLOT(updateFPS(float));
Run Code Online (Sandbox Code Playgroud)

否则,编译器会尝试调用另一个connect()驻留在全局范围内的函数,显然,这个函数使用不同的参数.