简体   繁体   中英

Qt4 slots and signals: Qt4 has trouble finding the signal

I am trying to get the statusbar to update with the FPS of the contents of a QGLWidget. I have connected them as follows (In class MainWin):

glWidget = new GLWidget;
ui.verticalLayout->addWidget(glWidget);

connect(glWidget,       SIGNAL( updateFPSSignal(float)  ),
        this,           SLOT(   updateFPSSlot(float)    ));
}

The slot is as follows:

void MainWin::updateFPSSlot(float fps){
this->statusBar()->showMessage(QString::number(fps), 0);
}

In the MainWin class definition, I have:

public slots:
    void updateFPSSlot(float fps);

And the signal is as follows: (From what I understand, this shouldn't be here, but the program refuses to compile without it).

void GLWidget::updateFPSSignal(float fps){}

I have the following in the GLWidget class definition:

signals:
    void updateFPSSignal(float fps);

After calculating the fps, I call:

emit updateFPSSignal(fps);

However, when the app starts up, the following is printed out:

Object::connect: No such signal QGLWidget::updateFPSSignal(float) in /Users/usm/Desktop/OGLTest/MainWin.cpp:12
Object::connect:  (receiver name: 'MainWinClass')

None of the tutorials I've read seem to be any help, and I'm sure the fix is simple for someone more experienced.

Thanks.

do you have

class GLWidget : public QGLWidget {

   Q_OBJECT

   /* ... rest of declaration ... */

};

in your class declaration? and have you put your glwidget.h header into the HEADERS section of your .pro file? the implementation of a signal is done by moc, not you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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