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. Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format)

Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format)

Scheduled Pinned Locked Moved Unsolved General and Desktop
crashqimagebug
15 Posts 4 Posters 1.9k Views
  • 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.
  • J JonB
    30 May 2022, 09:57

    @Wenchi
    So the trace shows you clicked a button and it called your CFuncToolSlamWidget::on_btn_add_clicked(). At line #263 that calls QImageReader::read(). So let's see the code around (i.e. leading up to) that line #263. We are probably particularly interested in the lifetime of the QImage you are using.

    W Offline
    W Offline
    Wenchi
    wrote on 30 May 2022, 10:19 last edited by
    #6

    @JonB
    I have already uploaded the code of function
    void CFuncToolSlamWidget::on_btn_add_clicked()
    to the description of the question.
    And the crash line is
    qImaggbk = reader.read();
    Since the crash doesn't appear necessarily, I couldn't figure out why it crashed.

    J 1 Reply Last reply 30 May 2022, 10:27
    0
    • W Wenchi
      30 May 2022, 10:19

      @JonB
      I have already uploaded the code of function
      void CFuncToolSlamWidget::on_btn_add_clicked()
      to the description of the question.
      And the crash line is
      qImaggbk = reader.read();
      Since the crash doesn't appear necessarily, I couldn't figure out why it crashed.

      J Offline
      J Offline
      JonB
      wrote on 30 May 2022, 10:27 last edited by
      #7

      @Wenchi
      Then it looks like QImageReader::read() does not like the content of the .png file you are trying to load. Does it happen depending on which file is chosen? Try the code with a specified filename in some standalone code outside of your project and see how it goes?

      W 1 Reply Last reply 31 May 2022, 03:38
      2
      • J Offline
        J Offline
        JoeCFD
        wrote on 30 May 2022, 14:30 last edited by JoeCFD
        #8

        Try to use another tool to load your image and see if the file is corrupt or has some other issues. It may be a good idea to check if read() fails or not all the time like the following:

        QImage icon(64, 64, QImage::Format_RGB32);
        QImageReader reader("icon_64x64.bmp");
        if (reader.read(&icon)) {
            // Display icon
        }
        

        the sample code is from here:
        https://doc.qt.io/qt-5/qimagereader.html#read-1

        W 1 Reply Last reply 31 May 2022, 03:48
        1
        • J JonB
          30 May 2022, 10:27

          @Wenchi
          Then it looks like QImageReader::read() does not like the content of the .png file you are trying to load. Does it happen depending on which file is chosen? Try the code with a specified filename in some standalone code outside of your project and see how it goes?

          W Offline
          W Offline
          Wenchi
          wrote on 31 May 2022, 03:38 last edited by
          #9

          @JonB
          I've tried that before. I coded while{...} to load the picture(png), which had caused crash, for over 1 million times, but the crash didn't appear.

          1 Reply Last reply
          0
          • J JoeCFD
            30 May 2022, 14:30

            Try to use another tool to load your image and see if the file is corrupt or has some other issues. It may be a good idea to check if read() fails or not all the time like the following:

            QImage icon(64, 64, QImage::Format_RGB32);
            QImageReader reader("icon_64x64.bmp");
            if (reader.read(&icon)) {
                // Display icon
            }
            

            the sample code is from here:
            https://doc.qt.io/qt-5/qimagereader.html#read-1

            W Offline
            W Offline
            Wenchi
            wrote on 31 May 2022, 03:48 last edited by
            #10

            @JoeCFD
            Thank you for your reply!
            Using another tool to load image can be a way to avoid the crash, but in my situstion, the crash could appear not only in QImageReader.read() but also in several other code, such as Qlist<MyWidget>.push_back() or QStackWidget.setCurrentIndex() and so on.

            C 1 Reply Last reply 31 May 2022, 15:32
            0
            • W Wenchi
              31 May 2022, 03:48

              @JoeCFD
              Thank you for your reply!
              Using another tool to load image can be a way to avoid the crash, but in my situstion, the crash could appear not only in QImageReader.read() but also in several other code, such as Qlist<MyWidget>.push_back() or QStackWidget.setCurrentIndex() and so on.

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 31 May 2022, 15:32 last edited by
              #11

              @Wenchi said in Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format):

              the crash could appear not only in QImageReader.read() but also in several other code, such as Qlist<MyWidget>.push_back() or QStackWidget.setCurrentIndex() and so on.

              Then you should fix your code.

              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
              0
              • W Offline
                W Offline
                Wenchi
                wrote on 6 Jun 2022, 09:00 last edited by
                #12

                please help!I'll lose my job if I can't fix this bug. crying

                J 1 Reply Last reply 6 Jun 2022, 10:14
                0
                • W Wenchi
                  6 Jun 2022, 09:00

                  please help!I'll lose my job if I can't fix this bug. crying

                  J Offline
                  J Offline
                  JonB
                  wrote on 6 Jun 2022, 10:14 last edited by
                  #13

                  @Wenchi
                  How do you expect anybody to offer any further help, if your code is crashing in various places?

                  W 1 Reply Last reply 7 Jun 2022, 07:44
                  0
                  • J JonB
                    6 Jun 2022, 10:14

                    @Wenchi
                    How do you expect anybody to offer any further help, if your code is crashing in various places?

                    W Offline
                    W Offline
                    Wenchi
                    wrote on 7 Jun 2022, 07:44 last edited by Wenchi 6 Aug 2022, 10:08
                    #14

                    @JonB
                    Although the code is crashing in various places, the crash point is always the same:

                    QImageData * QImageData::create(const QSize &size, QImage::Format format) )
                    

                    by the way, I'm fired. ready to get a new start

                    J 1 Reply Last reply 7 Jun 2022, 08:24
                    0
                    • W Wenchi
                      7 Jun 2022, 07:44

                      @JonB
                      Although the code is crashing in various places, the crash point is always the same:

                      QImageData * QImageData::create(const QSize &size, QImage::Format format) )
                      

                      by the way, I'm fired. ready to get a new start

                      J Offline
                      J Offline
                      JonB
                      wrote on 7 Jun 2022, 08:24 last edited by JonB 6 Jul 2022, 08:25
                      #15

                      @Wenchi said in Crash in function: QImageData * QImageData::create(const QSize &size, QImage::Format format):

                      Although the code is crashing in various places, but the crash point is always the same:

                      But that is likely --- or just as possible --- indicating you have a problem elsewhere which only shows up here, such as corrupted/misallocated memory? How else would you explain it "crashing" in e.g. QList<MyWidget>.push_back()?

                      by the way, I'm fired. ready to get a new start

                      I am sorry to hear that, good luck for future.

                      1 Reply Last reply
                      1

                      15/15

                      7 Jun 2022, 08:24

                      • Login

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