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. qpixmap::scaled: Pixmap is a null pixmap error on RELEASE, but works properly in DEBUG
Forum Updated to NodeBB v4.3 + New Features

qpixmap::scaled: Pixmap is a null pixmap error on RELEASE, but works properly in DEBUG

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.5k 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.
  • A Offline
    A Offline
    alberto2
    wrote on last edited by
    #1

    I'm compiling with MSVC2019-32 bits. On debug, it compiles and works properly. In release it compiles, but it wont render the image because of qpixmap::scaled: Pixmap is a null pixmap error.

    Any ideas why this might be happening?

    Thanks!

    jsulmJ 1 Reply Last reply
    0
    • A alberto2

      I'm compiling with MSVC2019-32 bits. On debug, it compiles and works properly. In release it compiles, but it wont render the image because of qpixmap::scaled: Pixmap is a null pixmap error.

      Any ideas why this might be happening?

      Thanks!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @alberto2 Can you show your code?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        Have you deployed the 32-bit release version of the image plugin(s) with your application?

        A 1 Reply Last reply
        2
        • jsulmJ jsulm

          @alberto2 Can you show your code?

          A Offline
          A Offline
          alberto2
          wrote on last edited by
          #4

          @jsulm

          void NoImagenState::cargarImagen() {
          QDesktopWidget desk;
          QRect screenres = desk.screenGeometry(0);

          QString selfilter = this->mw->tr("JPEG (*.jpg *.jpeg);; PNG (*.png)");
          
          QString path_name;
          
          QFileDialog dialog(
              this->mw,
              "Seleccionar Imagen",
              ".//imagenes//",
              selfilter);
          dialog.setFileMode(QFileDialog::ExistingFiles);
          dialog.setGeometry(QRect(screenres.width()/4,screenres.height() /4,screenres.width()/2,screenres.height()/2));
          dialog.show();
          if (dialog.exec())
              path_name = dialog.selectedFiles()[0];
          
          if (path_name == "") {
              mw->cambiarEstado(mw->getNoImagenState());
              return;
          }
          mw->set_imagen_name(path_name);
          QPixmap pix(path_name);
          mw->set_imagen_path(path_name);
          mw->set_imagen(pix);
          qDebug("hello");
          this->mw->ui->imagen->setPixmap(pix.scaledToHeight(this->mw->ui->imagen->height()));
          mw->cambiarEstado(mw->getImagenCargadaState());
          

          };

          Application output in RELEASE:
          hello
          QPixmap::scaleHeight: Pixmap is a null pixmap
          szValue=0

          Application output in DEBUG:
          hello
          ---------cambiando de estado a IMAGEN CARGADA-------------

          JonBJ 1 Reply Last reply
          0
          • C ChrisW67

            Have you deployed the 32-bit release version of the image plugin(s) with your application?

            A Offline
            A Offline
            alberto2
            wrote on last edited by
            #5

            @ChrisW67
            I'm sorry, I don't know what this plugin is.

            jsulmJ 1 Reply Last reply
            0
            • A alberto2

              @ChrisW67
              I'm sorry, I don't know what this plugin is.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @alberto2 Do you start the app from QtCreator?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A alberto2

                @jsulm

                void NoImagenState::cargarImagen() {
                QDesktopWidget desk;
                QRect screenres = desk.screenGeometry(0);

                QString selfilter = this->mw->tr("JPEG (*.jpg *.jpeg);; PNG (*.png)");
                
                QString path_name;
                
                QFileDialog dialog(
                    this->mw,
                    "Seleccionar Imagen",
                    ".//imagenes//",
                    selfilter);
                dialog.setFileMode(QFileDialog::ExistingFiles);
                dialog.setGeometry(QRect(screenres.width()/4,screenres.height() /4,screenres.width()/2,screenres.height()/2));
                dialog.show();
                if (dialog.exec())
                    path_name = dialog.selectedFiles()[0];
                
                if (path_name == "") {
                    mw->cambiarEstado(mw->getNoImagenState());
                    return;
                }
                mw->set_imagen_name(path_name);
                QPixmap pix(path_name);
                mw->set_imagen_path(path_name);
                mw->set_imagen(pix);
                qDebug("hello");
                this->mw->ui->imagen->setPixmap(pix.scaledToHeight(this->mw->ui->imagen->height()));
                mw->cambiarEstado(mw->getImagenCargadaState());
                

                };

                Application output in RELEASE:
                hello
                QPixmap::scaleHeight: Pixmap is a null pixmap
                szValue=0

                Application output in DEBUG:
                hello
                ---------cambiando de estado a IMAGEN CARGADA-------------

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

                @alberto2
                Please alter to following:

                qDebug() << path_name;
                QPixmap pix(path_name);
                qDebug() << pix.isNull();
                

                My guess is (as hinted bu @jsulm): the return value from path_name = dialog.selectedFiles()[0]; is a relative path, and it is relative to something other than the current working directory, perhaps when you run the Release executable outside of Creator whereas you run the Debug executable from within Creator?

                I don't know why you have pairs of /s in ".//imagenes//", it's not helpful. You also should not have a relative path here, since you do not know what the current directory will be at runtime. Make an absolute path to wherever this directory is, using QStandardPaths Class, choosing the entry in enum QStandardPaths::StandardLocation which best captures wherever you deploy to.

                You also should not have

                dialog.show();
                if (dialog.exec())
                    path_name = dialog.selectedFiles()[0];
                

                Remove the dialog.show(); here.

                A 1 Reply Last reply
                2
                • JonBJ JonB

                  @alberto2
                  Please alter to following:

                  qDebug() << path_name;
                  QPixmap pix(path_name);
                  qDebug() << pix.isNull();
                  

                  My guess is (as hinted bu @jsulm): the return value from path_name = dialog.selectedFiles()[0]; is a relative path, and it is relative to something other than the current working directory, perhaps when you run the Release executable outside of Creator whereas you run the Debug executable from within Creator?

                  I don't know why you have pairs of /s in ".//imagenes//", it's not helpful. You also should not have a relative path here, since you do not know what the current directory will be at runtime. Make an absolute path to wherever this directory is, using QStandardPaths Class, choosing the entry in enum QStandardPaths::StandardLocation which best captures wherever you deploy to.

                  You also should not have

                  dialog.show();
                  if (dialog.exec())
                      path_name = dialog.selectedFiles()[0];
                  

                  Remove the dialog.show(); here.

                  A Offline
                  A Offline
                  alberto2
                  wrote on last edited by
                  #8

                  @JonB
                  ok! Thanks for your tips. I finally got it to work.
                  The code was ok afterall, but in the release folder, inside the imageformats folder, some dlls were missing. I overwrote this folder with the one in C:\Qt\5.15.2\msvc2019\plugins\imageformats, and that solved the issue.

                  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