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. uchar* QImage::bits() returned '\0'...(nullptr)
Qt 6.11 is out! See what's new in the release blog

uchar* QImage::bits() returned '\0'...(nullptr)

Scheduled Pinned Locked Moved General and Desktop
17 Posts 4 Posters 3.6k 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 shtomik

    @mrjj

    So its from
    QImage QOpenGLWidget::grabFramebuffer() ?

    Yes.

    Did you check what
    http://doc.qt.io/qt-5/qimage.html#isNull
    says ?

    Yea, what's wrong? In debug mode I saw that image is 1280x720 and with data...

    Also, do you do something like
    https://stackoverflow.com/questions/13088749/efficient-conversion-of-avframe-to-qimage

    I read it, but I want to "convert" from QImage to AVFrame, not to QImage... I had a code for "converting" without data copy, but QImage::bits() func returned not correct pointer? If need to list code for converting, I can paste it, but is it correct way to think that my trouble really in bits() func? Thanks!

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

    @shtomik
    Hi
    ok so localImage is valid ?
    Normally its due to invalid image it returns null.
    But if in Format_RGB32 it should work.
    localImage bits() also returns null ?

    S 2 Replies Last reply
    0
    • mrjjM mrjj

      @shtomik
      Hi
      ok so localImage is valid ?
      Normally its due to invalid image it returns null.
      But if in Format_RGB32 it should work.
      localImage bits() also returns null ?

      S Offline
      S Offline
      shtomik
      wrote on last edited by
      #7

      @mrjj

      ok so localImage is valid ?
      localImage bits() also returns null ?

      localImage and img I can to QImage::save(QStrings path ...), and it's work... So I think valid... 1 minute, please, I check it in debug. Thanks again ;)

      1 Reply Last reply
      1
      • mrjjM mrjj

        @shtomik
        Hi
        ok so localImage is valid ?
        Normally its due to invalid image it returns null.
        But if in Format_RGB32 it should work.
        localImage bits() also returns null ?

        S Offline
        S Offline
        shtomik
        wrote on last edited by shtomik
        #8

        @mrjj
        Yes, is valid, I can save pic and not null... All is good, but what's wrong?(

        Now I'm using:

        QImage *img = new QImage(ui->oGLArea->grabFramebuffer());
        

        without localImage...

        mrjjM 1 Reply Last reply
        0
        • S shtomik

          @mrjj
          Yes, is valid, I can save pic and not null... All is good, but what's wrong?(

          Now I'm using:

          QImage *img = new QImage(ui->oGLArea->grabFramebuffer());
          

          without localImage...

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

          So
          After copying QImage to QImage, bits() fail ?
          QImage::QImage(const QImage &image)
          makes a shallow copy so i wonder if something goes out of scope ?
          If you do
          QImage img = ui->oGLArea->grabFramebuffer();
          is bits() still NULL ?
          Im wondering of the implicit sharing is doing something.

          S 1 Reply Last reply
          0
          • mrjjM mrjj

            So
            After copying QImage to QImage, bits() fail ?
            QImage::QImage(const QImage &image)
            makes a shallow copy so i wonder if something goes out of scope ?
            If you do
            QImage img = ui->oGLArea->grabFramebuffer();
            is bits() still NULL ?
            Im wondering of the implicit sharing is doing something.

            S Offline
            S Offline
            shtomik
            wrote on last edited by
            #10

            @mrjj
            I'm trying QImage::copy() too, but it's fail...

            If you do
            QImage img = ui->oGLArea->grabFramebuffer();
            is bits() still NULL ?

            Yes.

            mrjjM 1 Reply Last reply
            0
            • S shtomik

              @mrjj
              I'm trying QImage::copy() too, but it's fail...

              If you do
              QImage img = ui->oGLArea->grabFramebuffer();
              is bits() still NULL ?

              Yes.

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

              @shtomik
              Hmm. that is really odd if u can save them as working files.
              Im out of guesses.
              Give it some hours , others will come online and might have a good idea.

              S 1 Reply Last reply
              0
              • mrjjM mrjj

                @shtomik
                Hmm. that is really odd if u can save them as working files.
                Im out of guesses.
                Give it some hours , others will come online and might have a good idea.

                S Offline
                S Offline
                shtomik
                wrote on last edited by
                #12

                @mrjj
                thank you so much for your time and replies! I'm here... :)

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by VRonin
                  #13

                  what does qDebug() << QByteArray(reinterpret_cast<const char*>(img->constBits()),img->bytesPerLine()).size(); print out (if it doesn't crash)?

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  S 1 Reply Last reply
                  1
                  • mranger90M Offline
                    mranger90M Offline
                    mranger90
                    wrote on last edited by
                    #14

                    Are you sure its null ? By that I mean, what happens if you test

                      if ( bits == nullptr ) {
                       }
                    else {
                         qDebug () << *bits << *(bits + 1) << *(bits + 2)
                     }
                    

                    I ask because your description of whats shown in the debuggers sounds like the
                    debugger is looking at the first part of the pixel, which could be 0.

                    S 2 Replies Last reply
                    3
                    • VRoninV VRonin

                      what does qDebug() << QByteArray(reinterpret_cast<const char*>(img->constBits()),img->bytesPerLine()).size(); print out (if it doesn't crash)?

                      S Offline
                      S Offline
                      shtomik
                      wrote on last edited by
                      #15

                      @VRonin
                      It doesn't crash o_O
                      5120 - output

                      1 Reply Last reply
                      0
                      • mranger90M mranger90

                        Are you sure its null ? By that I mean, what happens if you test

                          if ( bits == nullptr ) {
                           }
                        else {
                             qDebug () << *bits << *(bits + 1) << *(bits + 2)
                         }
                        

                        I ask because your description of whats shown in the debuggers sounds like the
                        debugger is looking at the first part of the pixel, which could be 0.

                        S Offline
                        S Offline
                        shtomik
                        wrote on last edited by
                        #16

                        @mranger90
                        You are right! If first pixel not BLACK, debuger shows buffer of bits, but if first char - 0, empty buffer...

                        1 Reply Last reply
                        1
                        • mranger90M mranger90

                          Are you sure its null ? By that I mean, what happens if you test

                            if ( bits == nullptr ) {
                             }
                          else {
                               qDebug () << *bits << *(bits + 1) << *(bits + 2)
                           }
                          

                          I ask because your description of whats shown in the debuggers sounds like the
                          debugger is looking at the first part of the pixel, which could be 0.

                          S Offline
                          S Offline
                          shtomik
                          wrote on last edited by shtomik
                          #17

                          @mranger90 @VRonin @mrjj

                          Thank you guys... I found a couple of mistakes in my code, but the main mistake was in trust to the debugger, sometimes it was 0x0 or 0 or '\0' value for pointer to uchar that was 0.

                          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