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)

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

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