Setting QPixmap to Qlabel gives segmentation fault and app crashes
-
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.
-
Rather than giving the pointer to your MainWindow instance, pass directly the pointer to your label. Basically:
mainwindow->ui->label