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. Setting QPixmap to Qlabel gives segmentation fault and app crashes
Forum Updated to NodeBB v4.3 + New Features

Setting QPixmap to Qlabel gives segmentation fault and app crashes

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5qlabelqpixmapqimagegstreamer1.0
22 Posts 5 Posters 5.2k 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
    SGaist
    Lifetime Qt Champion
    wrote on 1 Apr 2020, 17:33 last edited by
    #13

    Which code exactly ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    V 1 Reply Last reply 9 Apr 2020, 14:00
    0
    • S SGaist
      1 Apr 2020, 17:33

      Which code exactly ?

      V Offline
      V Offline
      vicky_mac
      wrote on 9 Apr 2020, 14:00 last edited by
      #14

      @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.?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 9 Apr 2020, 14:02 last edited by
        #15

        @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.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 9 Apr 2020, 18:20 last edited by
          #16

          Something like:

          QMetaObject::invokeMethod(ui->label, "setPixmap", Qt::QueuedConnection, Q_ARG(pixmap));
          

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          V 1 Reply Last reply 11 Apr 2020, 06:02
          1
          • S SGaist
            9 Apr 2020, 18:20

            Something like:

            QMetaObject::invokeMethod(ui->label, "setPixmap", Qt::QueuedConnection, Q_ARG(pixmap));
            
            V Offline
            V Offline
            vicky_mac
            wrote on 11 Apr 2020, 06:02 last edited by
            #17

            @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);

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 11 Apr 2020, 06:23 last edited by
              #18

              Do you mean pass your MainWindow instance as the opaque data to your callback ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              V 1 Reply Last reply 13 Apr 2020, 10:44
              0
              • S SGaist
                11 Apr 2020, 06:23

                Do you mean pass your MainWindow instance as the opaque data to your callback ?

                V Offline
                V Offline
                vicky_mac
                wrote on 13 Apr 2020, 10:44 last edited by
                #19

                @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.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 13 Apr 2020, 11:27 last edited by
                  #20

                  I'd go a step further and pass directly the pointer to the QLabel object, it's even less instructions to use.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  V 1 Reply Last reply 15 Apr 2020, 12:05
                  0
                  • S SGaist
                    13 Apr 2020, 11:27

                    I'd go a step further and pass directly the pointer to the QLabel object, it's even less instructions to use.

                    V Offline
                    V Offline
                    vicky_mac
                    wrote on 15 Apr 2020, 12:05 last edited by
                    #21

                    @SGaist didn't get your point.
                    Can you please give example for above scenario

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 15 Apr 2020, 18:47 last edited by
                      #22

                      Rather than giving the pointer to your MainWindow instance, pass directly the pointer to your label. Basically:

                      mainwindow->ui->label
                      

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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