Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. GLWidget and Worker thread. UI freezes for update rates greater 15 Hz
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 471 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SaulGoodman
    wrote on last edited by
    #1

    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.

    @cWorker::cWorker()
    {
    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_dynamics->start(1000.0/upd_rate_dynamics);
    
    m_timer_graphics = new QTimer(this);
    connect(m_timer_graphics, SIGNAL( timeout() ), this, SLOT( updGraphics() ));
    m_timer_graphics->start(1000.0/upd_rate_graphics);
    

    }

    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;
    worker->moveToThread(thread);
    
    QObject::connect(thread, SIGNAL(started()), worker, SLOT(init()) );
    thread->start();
    
    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() ));
    
    w.show();
    return a.exec&#40;&#41;;
    

    }@

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved