tags:

views:

29

answers:

1

Hi, I've got a window containing a QGLWidget and a QStatusBar. I calculate the fps inside a timerEvent call, but I don't know the 'correct' way to update the statusbar on every frame. fps is a member variable of GLWidget:

void GLWidget::timerEvent(QTimerEvent* event){

    updateGL();

    // Calculate FPS.
    prevTime = currentTime;
    currentTime = runTime.elapsed();

    int timeDiff = currentTime - prevTime;

    fps = 1000.0/timeDiff;

    // Update statusbar with fps here.

}

Thanks!

+2  A: 

What you probably want is a custom signal on the GLWidget that you connect to a slot. Make the connection on the widget containing both the GLWidget and the status bar:

connect(&glWidgetInstance, SIGNAL(updateFPSSignal(int)), this, SLOT(updateFPSSlot(int)));

The slot function would look something like this:

void updateFPSSlot(int fps) {
    // Update status bar
}

Note that if the status bar is a custom class, you can create the slot function in that class, and connect directly to it. Either way, the connection should be made within the class that contains the instances for both the GLWidget and the status bar.

TreDubZedd
Thanks, I looked up some tutorials and the reference, but I can't find where to put the connect() function. I've tried putting it in the QMainWindow because that contains the GLWidget and statusbar, but the compiler says QMainWindow does not have a connect() function.
usm
QMainWindow is derived from QWidget, which is derived from QObject (which defines the connect function). Perhaps you're not using the Q_Object macro correctly in your QMainWindow?
TreDubZedd