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)
Forum Updated to NodeBB v4.3 + New Features

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 2.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.
  • Christian EhrlicherC Christian Ehrlicher

    Look where in your code the crash comes from and post the code (not screenshot). Also make sure the QImage data is valid during the whole lifetime of the QImage object (which I doubt it is) - how do you create your QImage object?

    WenchiW Offline
    WenchiW Offline
    Wenchi
    wrote on last edited by Wenchi
    #4

    @Christian-Ehrlicher @JonB
    Thank you for your reply! I have updated the description of my question. Could you see whether the information is enough. Since I haven't read the book, <Advanced Windows Debugging>, I'm afraid I couldn't provide more debug infomation.

    JonBJ 1 Reply Last reply
    0
    • WenchiW Wenchi

      @Christian-Ehrlicher @JonB
      Thank you for your reply! I have updated the description of my question. Could you see whether the information is enough. Since I haven't read the book, <Advanced Windows Debugging>, I'm afraid I couldn't provide more debug infomation.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #5

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

      WenchiW 1 Reply Last reply
      0
      • JonBJ JonB

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

        WenchiW Offline
        WenchiW Offline
        Wenchi
        wrote on 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.

        JonBJ 1 Reply Last reply
        0
        • WenchiW Wenchi

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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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?

          WenchiW 1 Reply Last reply
          2
          • JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on 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

            WenchiW 1 Reply Last reply
            1
            • JonBJ JonB

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

              WenchiW Offline
              WenchiW Offline
              Wenchi
              wrote on 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
              • JoeCFDJ JoeCFD

                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

                WenchiW Offline
                WenchiW Offline
                Wenchi
                wrote on 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.

                Christian EhrlicherC 1 Reply Last reply
                0
                • WenchiW Wenchi

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

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 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
                  • WenchiW Offline
                    WenchiW Offline
                    Wenchi
                    wrote on last edited by
                    #12

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

                    JonBJ 1 Reply Last reply
                    0
                    • WenchiW Wenchi

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

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #13

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

                      WenchiW 1 Reply Last reply
                      0
                      • JonBJ JonB

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

                        WenchiW Offline
                        WenchiW Offline
                        Wenchi
                        wrote on last edited by Wenchi
                        #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

                        JonBJ 1 Reply Last reply
                        0
                        • WenchiW Wenchi

                          @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

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #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

                          • Login

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