Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

    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();
}

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.

like image 902
rjacks Avatar asked Jan 27 '11 19:01

rjacks


People also ask

How to connect signal and slot in Qt?

To connect the signal to the slot, we use QObject::connect(). There are several ways to connect signal and slots. The first is to use function pointers: connect(sender, &QObject::destroyed, this, &MyObject::objectDestroyed);

How signal slot works in Qt?

The Qt signals/slots and property system are based on the ability to introspect the objects at runtime. Introspection means being able to list the methods and properties of an object and have all kinds of information about them such as the type of their arguments.


2 Answers

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.

like image 98
Fred Avatar answered Sep 22 '22 13:09

Fred


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

QObject::connect(gl, SIGNAL(fpsReport(float)), mWindow, SLOT(updateFPS(float));
like image 42
tibur Avatar answered Sep 23 '22 13:09

tibur