Unsolved Setting QPixmap to Qlabel gives segmentation fault and app crashes
-
@SGaist thank for suggestion ...
AS i am running qt version 5.11.3 and due to some resctrictions i cannot update it.
So i think QMetaObject::invokeMethod approch i'll have to follow . But i don't know how to use it.
Do you have any example code or any link where i can get some more details on this.*i tried copying the bufferInfo.data into another buffer and then did the image building and display. Then it works .. Don't know wther i should do this or not.
As suggested above i must not update UI from call back function . I'll try to use QMetaObject::invokeMethod and come back to you.
-
@SGaist can you please suggest how i can use QMetaObject::invokeMethod in this scenario. I am not able to figure it out.
-
Do you have a slot on your widget to set the QPixmap on the label ?
-
@SGaist No i was directly updating as given above in the coed.
I am not able to figure out on which event i should write the slot for label updation.
please suggest.
-
Which code exactly ?
-
@SGaist
In the question it self I have given code where I am updating the label.As I receive a frame in gst reamer thread I update it.
But how to do it in signal slot mechanism I am not able to feagure out. As you suggested above using qmetaobject how to use it in code.?
-
@vicky_mac said in Setting QPixmap to Qlabel gives segmentation fault and app crashes:
As I receive a frame in gst reamer thread I update it.
You are not allowed to modify the GUI from any thread except the main thread (better: the thread where QApplication lives in). Use signals/slots to update your ui.
-
Something like:
QMetaObject::invokeMethod(ui->label, "setPixmap", Qt::QueuedConnection, Q_ARG(pixmap));
-
@SGaist hi thanx for advise..
I did Qmetaobject::Invokemethod(self-ui->vdolabel, "setPixel", qtqueuedconnection, Q_Args(Qpixmap, P)) :And updating qlabel from setPixmap function in mainwidown.cpp its working fine.
Is it ok now or should have to anything else.
Is this OK passing the object reference and derefenrecing it like this?
MainWindow* self = static_cast<MainWindow* >(gSelf); -
Do you mean pass your MainWindow instance as the opaque data to your callback ?
-
@SGaist yes, because without that we would not Abe able to invoke method.
MainWindow* self = static_cast<MainWindow* >(gSelf);
This line...Because now by using Invokemethod I am updating qlabel in main thread and not child or gstreamer thread that seems OK.
-
I'd go a step further and pass directly the pointer to the QLabel object, it's even less instructions to use.
-
@SGaist didn't get your point.
Can you please give example for above scenario -
Rather than giving the pointer to your MainWindow instance, pass directly the pointer to your label. Basically:
mainwindow->ui->label