GLWidget and Worker thread. UI freezes for update rates greater 15 Hz

  • I have a Qt application with worker thread. The worker thread executes 2 functions void cWorker::updDynamics() and void cWorker::updGraphics() at different frequencies using 2 QTimer.

    updGraphics() connects to a slot in a class GLWidget : public QGLWidget in the main thread, which simply invokes updateGL();

    My problem is that my main window freezes (GL widget gets updated but I can't resize the window or click buttons) if my graphics update rate is > 15 Hz. Why is this happening and how can I avoid this problem? - I'd like to get 50Hz update at least.

    m_vertex = 0.1;

    void cWorker::init()
    int upd_rate_dynamics = 1000; //Hz
    int upd_rate_graphics = 15; //Hz

    m_timer_dynamics = new QTimer(this);
    connect(m_timer_dynamics, SIGNAL( timeout() ), this, SLOT( updDynamics() ));
    m_timer_graphics = new QTimer(this);
    connect(m_timer_graphics, SIGNAL( timeout() ), this, SLOT( updGraphics() ));


    void cWorker::updDynamics()
    std::cout << "cWorker::updDynamics()" << std::endl;
    m_vertex += 0.0005;

    void cWorker::updGraphics()
    std::cout << "cWorker::updGraphics()" << std::endl;
    emit requestRepaint();

    int main(int argc, char *argv[])

    cWorker* worker = new cWorker();
    QThread* thread = new QThread;
    QObject::connect(thread, SIGNAL(started()), worker, SLOT(init()) );
    QApplication a(argc, argv);
    MainWindow w;
    GLWidget *my_gl_widget = w.findChild<GLWidget*>("widget");
    my_gl_widget->m_worker_ptr = worker;
    QObject::connect(worker, SIGNAL( requestRepaint() ), my_gl_widget, SLOT( receiveRepaint() ));;
    return a.exec&#40;&#41;;


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.