Question

Got really stuck, need some advise or real examples.

1) I have boost::thread vector producer thread (data arrives fast ~ 100 samples per second) 2) I want QMathGL to paint data as it arrives 3) I don't want my Qt gui freeze

I tried to move QMathGL::update() to separate thread - Qt argues that QPixmap not allowed in separate thread.

What should i try, Without modifying QMathGL?

Only thing comes in mind to repaint on timer (fps?), but i don't like this solution, please tell me if i am wrong.

Was it helpful?

Solution 2

I´ve also come along a similar problem sometimes.

The usual resolution i used is to buffer the data and repainting on a timer. This goes along the line of this (Pseudo Code) :

void Widget::OnNewData(void *dataSample)
{
    this->threadSafebuffer->appendData(dataSample);
}
void Widget::OnTimeout()
{
    DataBuffer renderBatch = this->threadSafebuffer->interlockedExchange();
    /* Do UI updates according to renderBatch */

}

This assumes that OnNewData is called on a background thread. The OnTimeout is called from a QTimer on the UI-EventLoop. To prevent contention it justs does an interlocked exchange of the current buffer pointer with a second buffer. So no heavy synchronization (e.g. Mutext/Semaphore) is needed.

This will only work if the amount of work to do for rendering a renderBatch is less than the timeout.

OTHER TIPS

I would strongly advise to go with a timer. Repaint operations are costly and I would assume that no user could realistically process more then 10 printed vectors a second. So I can't see a real benefit for the end user, apart from maybe that the display is updated more "smoothly" and entry for entry. But you could achieve these effects far easier with animations ;)

When repainting with every data change, you get the annoying behaviour you describe. Working around that is (imho) not worth the trouble.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top