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. If statement to identify an image exists in a pixmap

If statement to identify an image exists in a pixmap

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.5k 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.
  • G Offline
    G Offline
    gergnnud
    wrote on last edited by
    #1

    I want to identify if a QLabel->pixmap is empty or not.

    This is because I want a button to open up an imageVewer (based on Qt example) to display a fullscreen view of the image in the pixmap but only if an image exists in the pixmap, otherwise don’t do anything.

    I have tried all sorts of things but cannot get this concept to work

    @ if(!ui->image_PreProcessed->pixmap()->isNull())
    {
    viewImage = new ImageViewer(this);
    viewImage->show();
    }@

    This is the only thing so far I have been able to compile but if there is no image in the pixmap it just crashes the application. If an image exists it works. I have declared viewImage in the header and all that works, so it’s just how to write the conditional part that I’m interested in.

    Any thoughts on where I’m going wrong?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should first check that ui->image_PreProcessed->pixmap() is not null

      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
      0
      • G Offline
        G Offline
        gergnnud
        wrote on last edited by
        #3

        Isn't that what I'm doing with !ui->... ?

        Do I also require an else statement to stop it crashing when it is null?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          No, your line checks whether the content of the QPixmap is null, not whether the QPixmap itself if null

          Depends on when you need imageView. Beware of one thing, you might be creating a memory leak with your current code.

          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
          0
          • G Offline
            G Offline
            gergnnud
            wrote on last edited by
            #5

            Thanks SGaist

            I will have to dig deeper then.

            Only need the imageView for zooming in to check focus as part of an initial config. Otherwise the application is being designed to run headless.

            I thought the QPixmap itself would never be null because it has height and width but I know very little about this stuff.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              The width/height doesn't depend on the pixmap set, it's the QLabel size.

              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
              0

              • Login

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