Megatron300 Megatron300 - 1 year ago 125
C++ Question

Qt emit taking 30ms, is that possible?

I'm trying to improve the performance of my project so I'm trying to figure out which operation is taking time.

I've noticed that my

function is taking 30ms, is that possible just to send data ?

Here is the code :

void MainWindow::play(){

unsigned char* img; //Size is 1280*720*2

img = camera1->captureLastFrame();


emit video(img);

qDebug()<<QString::number(timer.nsecsElapsed()/1000000) + " ms";


displays 30ms. I'm doing something wrong or is it really the time needed for that operation ?


Signal and slots declaration/connection.


void video(unsigned char* copy);

private slots:

void play();

connect(this, SIGNAL(video(unsigned char*)), ui->widget, SLOT(videodisplay(unsigned char*)));

Answer Source

If the connection is in a single thread, you perform the emit command and also the slot, then program continues to next row that's the qDebug one. So probably is not the signal slow, but the slot(s) that are connected to it.

Try to remove all connections using that signal, and adding it one at time in order to check the slow one. Or, better, try to use a profiler in order to check the bottleneck in this operation (valgrind on Linux, glowcode or similar in windows).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download