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. Couldn't loading .png or .jep picture,by qt create Running Executable

Couldn't loading .png or .jep picture,by qt create Running Executable

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 238 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.
  • M Offline
    M Offline
    Maybecute
    wrote 27 days ago last edited by Maybecute
    #1

    /picture on exe:/
    https://ddgobkiprc33d.cloudfront.net/952ef1f4-b4de-4456-9896-4214dd7d062e.png
    Loading fail!

    /*No thing in here */

    /On the .ui output/

    uisource.png

    picture loading successfully.

    /*Picture on the source coding */
    https://ddgobkiprc33d.cloudfront.net/84349671-5286-4288-8554-d42f09d3c9ed.png

    Loading successfully in .cpp sources code.

    Couldn't output on executable pictures maybe is qt cause or my
    Ubuntu I think.

    i need help,find the cause , after l can loading any
    picture on qt creator running exe.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Maybecute
      wrote 27 days ago last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kevin Hoang
        wrote 27 days ago last edited by Kevin Hoang
        #3

        Since the image path you're using is relative, it behaves differently depending on where the program is run from. When running from Qt Creator, the working directory is usually the project root, so a path like images/background.png works if the images folder is in your project directory.

        However, when you build and run the app outside of Qt Creator, the working directory becomes the folder where the executable is located (e.g., a build folder or wherever you've placed the compiled app). In that case, the relative path images/background.png might not be valid anymore.

        You have a couple of options to fix this:

        1. Copy the image folder to the same directory as your executable.
        2. Use a Qt resource file (.qrc) to embed the image directly into your application.
        J 1 Reply Last reply 27 days ago
        1
        • M Offline
          M Offline
          Maybecute
          wrote 27 days ago last edited by
          #4

          Is not .qrc path problems , i think my exe don't understand what is the picture?,so l should be write some codes,let my exe know , what is the picture nya~~(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)

          M 1 Reply Last reply 27 days ago
          0
          • M Maybecute
            27 days ago

            Is not .qrc path problems , i think my exe don't understand what is the picture?,so l should be write some codes,let my exe know , what is the picture nya~~(⁠◍⁠•⁠ᴗ⁠•⁠◍⁠)

            M Offline
            M Offline
            Maybecute
            wrote 27 days ago last edited by
            #5

            @Maybecute the exe can read and load .txt .log
            .cxx, only read text information , If it can loading about picture example " .png ", " . jep "and more . ,my problem maybe solved.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote 27 days ago last edited by
              #6

              @Kevin-Hoang is right. It's a path problem. Use QFile::exists() so you can see that he is correct.

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

              1 Reply Last reply
              0
              • K Kevin Hoang
                27 days ago

                Since the image path you're using is relative, it behaves differently depending on where the program is run from. When running from Qt Creator, the working directory is usually the project root, so a path like images/background.png works if the images folder is in your project directory.

                However, when you build and run the app outside of Qt Creator, the working directory becomes the folder where the executable is located (e.g., a build folder or wherever you've placed the compiled app). In that case, the relative path images/background.png might not be valid anymore.

                You have a couple of options to fix this:

                1. Copy the image folder to the same directory as your executable.
                2. Use a Qt resource file (.qrc) to embed the image directly into your application.
                J Offline
                J Offline
                JonB
                wrote 27 days ago last edited by JonB
                #7

                @Kevin-Hoang said in Couldn't loading .png or .jep picture,by qt create Running Executable:

                However, when you build and run the app outside of Qt Creator, the working directory becomes the folder where the executable is located (e.g., a build folder or wherever you've placed the compiled app).

                No it does not. Running an executable does not change the working directory in any way, and not to where the executable is located. Working directory is inherited (or set) from caller. It is possible that OS/windowing system allows user to specify a current directory e.g. on an icon/shortcut to run it, but that is another matter. Not to mention that an executable can change the current directory itself any time, e.g. before trying to access the relative path. All of which makes it even more important that coder think about how they specify paths or what directories to use.

                This means that your "Copy the image folder to the same directory as your executable." is not at all a guarantee it will be found via a relative path. Don't use relative paths unless you really mean "relative to whatever the current directory happens to be", which is not suitable for locating supplied files.

                P.S.
                If you really want to locate files relative to where the executable lives use QCoreApplication::applicationDirPath() in code to build an absolute path. Even then note this is not robust, at minimum under Linux.

                M 1 Reply Last reply 26 days ago
                0
                • M Offline
                  M Offline
                  Maybecute
                  wrote 26 days ago last edited by Maybecute
                  #8

                  Find the reason at https://forum.qt.io/topic/71836/how-to-display-a-picture/17

                  Screenshot From 2025-04-17 05-44-06.png

                  Now is successful load pictures on application,
                  Picture loading path couldn't is .qrc , should be
                  /Home add new Folders to save of picture .
                  and add some main code at transformat::transformat

                  /*
                  note: picture path could not is /test_background/picture name.jpg
                  It's is .qrc loading path,not applicable output 
                  Picture path.
                  */
                  
                  
                  Qpixmap setpicture{”home/background pictures/picture name.jpg"};
                  ui->setpic->setPixmap(setpicrure);
                  ui->setpic->setScaledContent(true);
                  
                  1 Reply Last reply
                  0
                  • M Maybecute has marked this topic as solved 26 days ago
                  • J JonB
                    27 days ago

                    @Kevin-Hoang said in Couldn't loading .png or .jep picture,by qt create Running Executable:

                    However, when you build and run the app outside of Qt Creator, the working directory becomes the folder where the executable is located (e.g., a build folder or wherever you've placed the compiled app).

                    No it does not. Running an executable does not change the working directory in any way, and not to where the executable is located. Working directory is inherited (or set) from caller. It is possible that OS/windowing system allows user to specify a current directory e.g. on an icon/shortcut to run it, but that is another matter. Not to mention that an executable can change the current directory itself any time, e.g. before trying to access the relative path. All of which makes it even more important that coder think about how they specify paths or what directories to use.

                    This means that your "Copy the image folder to the same directory as your executable." is not at all a guarantee it will be found via a relative path. Don't use relative paths unless you really mean "relative to whatever the current directory happens to be", which is not suitable for locating supplied files.

                    P.S.
                    If you really want to locate files relative to where the executable lives use QCoreApplication::applicationDirPath() in code to build an absolute path. Even then note this is not robust, at minimum under Linux.

                    M Offline
                    M Offline
                    Maybecute
                    wrote 26 days ago last edited by
                    #9

                    @JonB
                    Thank you i application is normally running
                    Pictures (⁠◠⁠‿⁠◕⁠) .
                    Screenshot From 2025-04-17 05-44-06.png

                    1 Reply Last reply
                    0

                    1/9

                    16 Apr 2025, 07:01

                    • Login

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