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. QImage to Qpixmap conversion is too slow

QImage to Qpixmap conversion is too slow

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 4 Posters 7.1k Views 3 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.
  • L lansing

    @mrjj

    Hi This is what I have done so far:

    class MyGLPainter : public QOpenGLWidget
    {
        Q_OBJECT
    public:
        MyGLPainter (QWidget *parent = nullptr);
        void paintEvent(QPaintEvent *) override;
        void drawImage(const QImage &image); 
    
    private:
        QImage m_frameImage;
    
    MyGLPainter::MyGLPainter (QWidget *parent): QOpenGLWidget(parent)  
    {
    }
    
    void MyGLPainter::paintEvent(QPaintEvent *)
    {
        QPainter painter(this);   
        painter.drawImage(m_frameImage.width(),m_frameImage.height(), m_frameImage);
        painter.end();
    }
    
    void MyGLPainter::drawImage(const QImage &image)
    {
        m_frameImage = image;
        update();
    }
    

    But when I pass the image to drawImage(), the program will just crash. Am I doing this correctly?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #10

    @lansing
    Hi
    It looks ok.
    In what lines does it crash ?

    L 1 Reply Last reply
    0
    • mrjjM mrjj

      @lansing
      Hi
      It looks ok.
      In what lines does it crash ?

      L Offline
      L Offline
      lansing
      wrote on last edited by lansing
      #11

      @mrjj

      At the line update(). It points to function QImage::operator=

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #12

        Do you update your image from a different thread? If so you should learn about threading: Threading Basics

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

        L 1 Reply Last reply
        3
        • Christian EhrlicherC Christian Ehrlicher

          Do you update your image from a different thread? If so you should learn about threading: Threading Basics

          L Offline
          L Offline
          lansing
          wrote on last edited by
          #13

          @Christian-Ehrlicher

          HI, is this related to the crash?

          mrjjM 1 Reply Last reply
          0
          • L lansing

            @Christian-Ehrlicher

            HI, is this related to the crash?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #14

            @lansing

            Hi
            yes if you do it from another thread then very much yes.

            L 1 Reply Last reply
            0
            • mrjjM mrjj

              @lansing

              Hi
              yes if you do it from another thread then very much yes.

              L Offline
              L Offline
              lansing
              wrote on last edited by
              #15

              @mrjj

              I don't have threading in the program.

              mrjjM 1 Reply Last reply
              0
              • L lansing

                @mrjj

                I don't have threading in the program.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #16

                @lansing
                Hi
                then something is wrong with the image then.
                Else why crash on copy.

                can you try with Image that you are 100% sure is valid ?

                L 1 Reply Last reply
                0
                • mrjjM mrjj

                  @lansing
                  Hi
                  then something is wrong with the image then.
                  Else why crash on copy.

                  can you try with Image that you are 100% sure is valid ?

                  L Offline
                  L Offline
                  lansing
                  wrote on last edited by lansing
                  #17

                  @mrjj

                  Hi, I have set the image to one in my resource folder for testing, now it has crashed at line m_frameImage = image. I have changed the image argument from const QImage & to QImage*, I don't know if that have a effect on it. But in debug, it did show my image dimension.

                  QImage *img= new QImage(":/cross.png");
                  myGLPainter->drawImage(img);
                  
                  mrjjM Christian EhrlicherC SGaistS 3 Replies Last reply
                  0
                  • L lansing

                    @mrjj

                    Hi, I have set the image to one in my resource folder for testing, now it has crashed at line m_frameImage = image. I have changed the image argument from const QImage & to QImage*, I don't know if that have a effect on it. But in debug, it did show my image dimension.

                    QImage *img= new QImage(":/cross.png");
                    myGLPainter->drawImage(img);
                    
                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #18

                    @lansing
                    and it does still crash ?

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lansing
                      wrote on last edited by
                      #19

                      Yes, it said

                      error: Debugger encountered an exception: Exception at 0x7ff71b7e9b88, code: 0xc0000005: read access violation at: 0xffffffffffffffff, flags=0x0
                      
                      1 Reply Last reply
                      0
                      • L lansing

                        @mrjj

                        Hi, I have set the image to one in my resource folder for testing, now it has crashed at line m_frameImage = image. I have changed the image argument from const QImage & to QImage*, I don't know if that have a effect on it. But in debug, it did show my image dimension.

                        QImage *img= new QImage(":/cross.png");
                        myGLPainter->drawImage(img);
                        
                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #20

                        @lansing said in QImage to Qpixmap conversion is too slow:

                        myGLPainter

                        Where do you initialize this variable?

                        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
                        • L lansing

                          @mrjj

                          Hi, I have set the image to one in my resource folder for testing, now it has crashed at line m_frameImage = image. I have changed the image argument from const QImage & to QImage*, I don't know if that have a effect on it. But in debug, it did show my image dimension.

                          QImage *img= new QImage(":/cross.png");
                          myGLPainter->drawImage(img);
                          
                          SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #21

                          @lansing said in QImage to Qpixmap conversion is too slow:

                          QImage *img= new QImage(":/cross.png");
                          myGLPainter->drawImage(img);

                          That's the wrong thing to do as you will leak images doing so.

                          Beside the initialization issue pointed by @Christian-Ehrlicher can you provide the stack trace of your crash ?

                          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
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved