开发者

Simple Qt App refuses to compile once a signal/slot is added

So basically, I am making a very simple Qt app to help me along as I learn OpenGL. The idea

is that I have two windows, one is a GL context (GLWidget, derived from QGLWidget) and the other is a simple GUI with a couple of progress bars and a text area.

I can get the app to compile and run, and everything is beautiful UNTIL I tried to connect signals and slot between the two windows. I have read through the docs on QGLWidget, the official tutorial on signals and slots, and the documentation for int connect().

To illustrate: my main.cpp file:

#include <QApplication>
#include <QObject>

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

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

    Mai开发者_StackOverflow中文版nWindow *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();
}

The specific compiler errors I am getting are:

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)'

Not sure if this is relevant, but I'm using Qt Creator 2.0.1, based on Qt 4.7.0 (32 bit). Running 32-bit Windows 7 Ultimate.


connect is a static member of QObject. When used outside of a QObject context, you need to specify the scope as such :

QObject::connect(gl, SIGNAL(fpsReport(float)), mWindow, SLOT(updateFPS(float));

Otherwise, the compiler tries to call another function called connect() which resides in the global scope, and obviously, this other function uses different parameters.


You're trying to use the connect function from windows socket API. Try:

QObject::connect(gl, SIGNAL(fpsReport(float)), mWindow, SLOT(updateFPS(float));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜