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 not show in .exe file

QPixmap not show in .exe file

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 1.1k 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.
  • I Offline
    I Offline
    iliahero
    wrote on last edited by
    #1

    hi. i use this code to showing pixmap:

    MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
            QPixmap pm(":/img/board/tic.jpg");
            ui->board->setScaledContents(true);
            ui->board->setPixmap(pm);
        }
        
    

    this code work when i run my app in release mode in qtcreator but in release folder when i click on .exe file its dont work and this code dont showing the picture.
    but when i use the directory of my img(like this: C://dir/dir/...) its showing my picture.

    sorry if im not good in english. please help!

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      How do you deploy your executable? Use windeployqt - it deploys all required plugins (in your case the jpg image plugin).

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      I 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        How do you deploy your executable? Use windeployqt - it deploys all required plugins (in your case the jpg image plugin).

        I Offline
        I Offline
        iliahero
        wrote on last edited by
        #3

        @Christian-Ehrlicher i use this command :
        windeployqt.exe --quick .

        JonBJ 1 Reply Last reply
        0
        • I Offline
          I Offline
          iliahero
          wrote on last edited by
          #4

          i dont think my problem is from deploy becuse when i use this code its showing my picture:

          QPixmap pm("C:/Users/Other/Desktop/img1.jpg");
              ui->board->setScaledContents(true);
              ui->board->setPixmap(pm);
          

          i think my problem is from loading picture in recourse file in my project

          1 Reply Last reply
          0
          • I iliahero

            @Christian-Ehrlicher i use this command :
            windeployqt.exe --quick .

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

            @iliahero
            In your code put in qDebug() << QFile::exists(":/img/board/tic.jpg"); (or whatever suitable in place of qDebug()). That tells you whether the file exists. Assuming that returns true the issue is with showing the pixmap, maybe as @Christian-Ehrlicher said; if it returns false you have some other problem.

            I 1 Reply Last reply
            0
            • JonBJ JonB

              @iliahero
              In your code put in qDebug() << QFile::exists(":/img/board/tic.jpg"); (or whatever suitable in place of qDebug()). That tells you whether the file exists. Assuming that returns true the issue is with showing the pixmap, maybe as @Christian-Ehrlicher said; if it returns false you have some other problem.

              I Offline
              I Offline
              iliahero
              wrote on last edited by
              #6

              @JonB returned true

              JonBJ 1 Reply Last reply
              0
              • I iliahero

                @JonB returned true

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

                @iliahero
                So as @Christian-Ehrlicher says it looks like the deployed version has trouble showing a .jpg file. Look in what windeployqt has packaged for your executable, does it contain anything like a plugin to do with showing JPEGs?

                I 1 Reply Last reply
                0
                • JonBJ JonB

                  @iliahero
                  So as @Christian-Ehrlicher says it looks like the deployed version has trouble showing a .jpg file. Look in what windeployqt has packaged for your executable, does it contain anything like a plugin to do with showing JPEGs?

                  I Offline
                  I Offline
                  iliahero
                  wrote on last edited by
                  #8

                  @JonB
                  i use this command :
                  windeployqt.exe --quick .

                  my release folder have a folder named imgformats its have :
                  qgif, gicn, qico, qjpeg, qsvg, qtgs, qtiff, qwbmp, qwebm.

                  but as i said i think the problem is not from deploy becuse when i use the path of my img in my desktop and deploy my project its showing pixmap

                  JonBJ 1 Reply Last reply
                  0
                  • hskoglundH Online
                    hskoglundH Online
                    hskoglund
                    wrote on last edited by
                    #9

                    Maybe it's a confusion/mixup of filenames, you have
                    ":/img/board/tic.jpg" and C:/Users/Other/Desktop/img1.jpg, not the same file?

                    I 1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      iliahero
                      wrote on last edited by
                      #10

                      thank for your helps
                      my problem solved
                      The problem was with my system

                      JonBJ 1 Reply Last reply
                      0
                      • hskoglundH hskoglund

                        Maybe it's a confusion/mixup of filenames, you have
                        ":/img/board/tic.jpg" and C:/Users/Other/Desktop/img1.jpg, not the same file?

                        I Offline
                        I Offline
                        iliahero
                        wrote on last edited by
                        #11

                        @hskoglund my problem solved

                        thanks

                        1 Reply Last reply
                        0
                        • I iliahero

                          @JonB
                          i use this command :
                          windeployqt.exe --quick .

                          my release folder have a folder named imgformats its have :
                          qgif, gicn, qico, qjpeg, qsvg, qtgs, qtiff, qwbmp, qwebm.

                          but as i said i think the problem is not from deploy becuse when i use the path of my img in my desktop and deploy my project its showing pixmap

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

                          @iliahero
                          Yes, I understand it is weird if it works from an external .jpg file but not from one in a resource which you have checked exists. I do not have an explanation for that.

                          Unless somehow the resource image does not contain what you think it does.

                          • Get rid of setScaledContents() just in case that is a problem.

                          • Discover whether on the line after QPixmap pm("C:/Users/Other/Desktop/img1.jpg"); that qDebug() << pm.isNull(); returns true or false.

                          • For the sake of a few minutes coding, try in your code extracting :/img/board/tic.jpg to an external file and then setting that as a pixmap. Look at the extracted file and see if it is correct.

                          1 Reply Last reply
                          0
                          • I iliahero

                            thank for your helps
                            my problem solved
                            The problem was with my system

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

                            @iliahero said in QPixmap not show in .exe file:

                            The problem was with my system

                            What does that mean, given that you had checked the file was valid and the deployed image had the necessary plugins?

                            1 Reply Last reply
                            0
                            • I Offline
                              I Offline
                              iliahero
                              wrote on last edited by
                              #14

                              my project was created on "example" directory. i copy my project to another directory
                              but when i deploy my project, its deploy the older version of my project.
                              sorry im not good in english.

                              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