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. problem with paths (or QPainter)
Forum Updated to NodeBB v4.3 + New Features

problem with paths (or QPainter)

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 6 Posters 2.8k Views 4 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.
  • L loa3

    Guys, this app is just for drawing methods (classes) learning purposes and will not be used as 'real' application. Moreover, programs (in future) will be written for PLCs (i.e. embedded linux).
    So it is enough just to grab dozen of .jpeg pictures somehow. But I can not ((

    Path with ../../img/ as Artur advised earlier is also gives 'invalid' object...

    artwawA Offline
    artwawA Offline
    artwaw
    wrote on last edited by
    #9

    @loa3 there should be at least one more .., my bad.

    Initial . points to the YourProgram.app\Contents\MacOS\

    For more information please re-read.

    Kind Regards,
    Artur

    1 Reply Last reply
    0
    • M mpergand

      For testing purpose only, you can do:

      Put your img dir at the same level as lesson9 dir

      in your code do:

          QDir dir(QCoreApplication::applicationDirPath());
          dir.cdUp();
          dir.cdUp();
          dir.cdUp();
          dir.cdUp();
      // or dir.cd("../../../../");
          dir.cd("img");
              
          qDebug()<<dir.path()<< dir.exists();
      
      L Offline
      L Offline
      loa3
      wrote on last edited by
      #10

      @mpergand said in problem with paths (or QPainter):

      For testing purpose only, you can do:

      Put your img dir at the same level as lesson9 dir

      in your code do:

          QDir dir(QCoreApplication::applicationDirPath());
          dir.cdUp();
          dir.cdUp();
          dir.cdUp();
          dir.cdUp();
      // or dir.cd("../../../../");
          dir.cd("img");
              
          qDebug()<<dir.path()<< dir.exists();
      

      I've done very close:
      ```
      QDir dir(QCoreApplication::applicationDirPath());

      dir.cdUp();
      qDebug()<<dir.path();
      dir.cdUp();
      qDebug()<<dir.path();
      dir.cdUp();
      qDebug()<<dir.path();
      dir.cdUp();
      qDebug()<<dir.path();
      
      dir.cd("img");
      
      qDebug() << dir.path() << dir.exists();
      
      qDebug() << star_background.load("star_background.jpg");
      
      
      It gives such debug log:
      
      "/Users/apple/Google Drive/Electro/plc-edu/CPP/L9/build-lesson9-Desktop_Qt_5_15_2_clang_64bit-Debug/lesson9.app/Contents"
      "/Users/apple/Google Drive/Electro/plc-edu/CPP/L9/build-lesson9-Desktop_Qt_5_15_2_clang_64bit-Debug/lesson9.app"
      "/Users/apple/Google Drive/Electro/plc-edu/CPP/L9/build-lesson9-Desktop_Qt_5_15_2_clang_64bit-Debug"
      "/Users/apple/Google Drive/Electro/plc-edu/CPP/L9"
      "/Users/apple/Google Drive/Electro/plc-edu/CPP/L9/img" true
      false
      
      So the problem seems to me in QImage::load()?
      artwawA 1 Reply Last reply
      0
      • M Offline
        M Offline
        mpergand
        wrote on last edited by
        #11
        QString path=dir.filePath("star_background.jpg");
        star_background.load(path);
        
        1 Reply Last reply
        0
        • L loa3

          @mpergand said in problem with paths (or QPainter):

          For testing purpose only, you can do:

          Put your img dir at the same level as lesson9 dir

          in your code do:

              QDir dir(QCoreApplication::applicationDirPath());
              dir.cdUp();
              dir.cdUp();
              dir.cdUp();
              dir.cdUp();
          // or dir.cd("../../../../");
              dir.cd("img");
                  
              qDebug()<<dir.path()<< dir.exists();
          

          I've done very close:
          ```
          QDir dir(QCoreApplication::applicationDirPath());

          dir.cdUp();
          qDebug()<<dir.path();
          dir.cdUp();
          qDebug()<<dir.path();
          dir.cdUp();
          qDebug()<<dir.path();
          dir.cdUp();
          qDebug()<<dir.path();
          
          dir.cd("img");
          
          qDebug() << dir.path() << dir.exists();
          
          qDebug() << star_background.load("star_background.jpg");
          
          
          It gives such debug log:
          
          "/Users/apple/Google Drive/Electro/plc-edu/CPP/L9/build-lesson9-Desktop_Qt_5_15_2_clang_64bit-Debug/lesson9.app/Contents"
          "/Users/apple/Google Drive/Electro/plc-edu/CPP/L9/build-lesson9-Desktop_Qt_5_15_2_clang_64bit-Debug/lesson9.app"
          "/Users/apple/Google Drive/Electro/plc-edu/CPP/L9/build-lesson9-Desktop_Qt_5_15_2_clang_64bit-Debug"
          "/Users/apple/Google Drive/Electro/plc-edu/CPP/L9"
          "/Users/apple/Google Drive/Electro/plc-edu/CPP/L9/img" true
          false
          
          So the problem seems to me in QImage::load()?
          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #12

          @loa3 said in problem with paths (or QPainter):

          So the problem seems to me in QImage::load()?

          No quite, the problem is that you do not address your paths in the system independent way. Hence the load() fails.

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          0
          • L Offline
            L Offline
            loa3
            wrote on last edited by
            #13

            Oh, yeah!
            It works! And I slightly understand what was the trouble.
            But it's not easy to realize how .app file may be both executable and also 'directory' for it's data.
            Anyway now I can continue my play with images.

            Many thanks!

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

              Hi,

              @loa3 said in problem with paths (or QPainter):

              .app file may be both executable and also 'directory' for it's data.

              They are not both. In fact they are specially treated folders. Look for app bundle in macOS developer documentation.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              L 1 Reply Last reply
              0
              • M Offline
                M Offline
                mpergand
                wrote on last edited by mpergand
                #15

                For those who targetting MacOS (IOS ?) only,
                it's possible to use the app bundle as a resources container.

                To copy the contents of a folder in the Resources folder in the app bundle, add the folllowing in the .pro file:

                # the img folder is in the project folder (same level as the project file)
                IMAGES.files = $$files(img/*.jpg)
                IMAGES.path = contents/resources/img
                QMAKE_BUNDLE_DATA += IMAGES
                

                Note that the img folder is created automatically if it doesn't exist , cool feature !

                I try to do the same things the Qt way with RESOURCES
                RESOURCES +=$$files(img/*.jpg)
                the folder appears in the left panel hierarchy tree, but it doesn't work because no qrc is created.

                Any magic command for that ?

                L artwawA 2 Replies Last reply
                0
                • SGaistS SGaist

                  Hi,

                  @loa3 said in problem with paths (or QPainter):

                  .app file may be both executable and also 'directory' for it's data.

                  They are not both. In fact they are specially treated folders. Look for app bundle in macOS developer documentation.

                  L Offline
                  L Offline
                  loa3
                  wrote on last edited by
                  #16

                  @SGaist said in problem with paths (or QPainter):

                  They are not both. In fact they are specially treated folders. Look for app bundle in macOS developer documentation.

                  I understand. It was like a joke (take into account my poor English).

                  1 Reply Last reply
                  0
                  • M mpergand

                    For those who targetting MacOS (IOS ?) only,
                    it's possible to use the app bundle as a resources container.

                    To copy the contents of a folder in the Resources folder in the app bundle, add the folllowing in the .pro file:

                    # the img folder is in the project folder (same level as the project file)
                    IMAGES.files = $$files(img/*.jpg)
                    IMAGES.path = contents/resources/img
                    QMAKE_BUNDLE_DATA += IMAGES
                    

                    Note that the img folder is created automatically if it doesn't exist , cool feature !

                    I try to do the same things the Qt way with RESOURCES
                    RESOURCES +=$$files(img/*.jpg)
                    the folder appears in the left panel hierarchy tree, but it doesn't work because no qrc is created.

                    Any magic command for that ?

                    L Offline
                    L Offline
                    loa3
                    wrote on last edited by
                    #17

                    @mpergand said in problem with paths (or QPainter):

                    For those who targetting MacOS (IOS ?) only,
                    it's possible to use the app bundle as a resources container.

                    It is very helpful information. I proposed that something like this.

                    But in fact now my apps should be 'universal'. Since the 'teacher' use Win to check my exercises (as well as Qt with MinGW).

                    1 Reply Last reply
                    0
                    • M mpergand

                      For those who targetting MacOS (IOS ?) only,
                      it's possible to use the app bundle as a resources container.

                      To copy the contents of a folder in the Resources folder in the app bundle, add the folllowing in the .pro file:

                      # the img folder is in the project folder (same level as the project file)
                      IMAGES.files = $$files(img/*.jpg)
                      IMAGES.path = contents/resources/img
                      QMAKE_BUNDLE_DATA += IMAGES
                      

                      Note that the img folder is created automatically if it doesn't exist , cool feature !

                      I try to do the same things the Qt way with RESOURCES
                      RESOURCES +=$$files(img/*.jpg)
                      the folder appears in the left panel hierarchy tree, but it doesn't work because no qrc is created.

                      Any magic command for that ?

                      artwawA Offline
                      artwawA Offline
                      artwaw
                      wrote on last edited by
                      #18

                      @mpergand said in problem with paths (or QPainter):

                      it doesn't work because no qrc is created.

                      Again: Qt way to handle it is to create resource file and put the images in the resource file. This way when the bundle is created all the resources are properly put.
                      Modifying app bundle by putting surplus data in it is not advisable. You might run into the problems later, when signing and verifying deployment bundle.
                      Besides, there is not need to reinvent the wheel.

                      For more information please re-read.

                      Kind Regards,
                      Artur

                      1 Reply Last reply
                      1
                      • M Offline
                        M Offline
                        mpergand
                        wrote on last edited by
                        #19

                        @artwaw said in problem with paths (or QPainter):

                        Modifying app bundle by putting surplus data in it is not advisable. Y

                        macx {
                        QMAKE_INFO_PLIST = Mac/Info.plist
                        ICON = Mac/AppIcon.icns
                        }

                        Where do you think these two files go ?

                        A bundle is a directory with a standardized hierarchical structure that holds executable code and the resources used by that code. The bundle contains resources that may be accessed at runtime, such as images, audio files, user interface files, and property lists.
                        If you don’t use Xcode to build your software product, use the information below to place your bundled content in the right location.
                        If you put content in the wrong location, you may encounter hard-to-debug code signing and distribution problems.

                        All that seems obvious, but what's wrong with Qt Apps ?
                        If there are issues, it is a Qt problem, not mine.

                        artwawA J.HilkJ 2 Replies Last reply
                        0
                        • M mpergand

                          @artwaw said in problem with paths (or QPainter):

                          Modifying app bundle by putting surplus data in it is not advisable. Y

                          macx {
                          QMAKE_INFO_PLIST = Mac/Info.plist
                          ICON = Mac/AppIcon.icns
                          }

                          Where do you think these two files go ?

                          A bundle is a directory with a standardized hierarchical structure that holds executable code and the resources used by that code. The bundle contains resources that may be accessed at runtime, such as images, audio files, user interface files, and property lists.
                          If you don’t use Xcode to build your software product, use the information below to place your bundled content in the right location.
                          If you put content in the wrong location, you may encounter hard-to-debug code signing and distribution problems.

                          All that seems obvious, but what's wrong with Qt Apps ?
                          If there are issues, it is a Qt problem, not mine.

                          artwawA Offline
                          artwawA Offline
                          artwaw
                          wrote on last edited by
                          #20

                          @mpergand There is nothing wrong with Qt Apps.
                          My point is that there no need to fiddle with resources (and rare case when you need to adjust info.plist) since Qt offers you ready solutions to handle it.

                          @mpergand said in problem with paths (or QPainter):

                          If there are issues, it is a Qt problem, not mine.

                          O'rly

                          For more information please re-read.

                          Kind Regards,
                          Artur

                          1 Reply Last reply
                          0
                          • M mpergand

                            @artwaw said in problem with paths (or QPainter):

                            Modifying app bundle by putting surplus data in it is not advisable. Y

                            macx {
                            QMAKE_INFO_PLIST = Mac/Info.plist
                            ICON = Mac/AppIcon.icns
                            }

                            Where do you think these two files go ?

                            A bundle is a directory with a standardized hierarchical structure that holds executable code and the resources used by that code. The bundle contains resources that may be accessed at runtime, such as images, audio files, user interface files, and property lists.
                            If you don’t use Xcode to build your software product, use the information below to place your bundled content in the right location.
                            If you put content in the wrong location, you may encounter hard-to-debug code signing and distribution problems.

                            All that seems obvious, but what's wrong with Qt Apps ?
                            If there are issues, it is a Qt problem, not mine.

                            J.HilkJ Offline
                            J.HilkJ Offline
                            J.Hilk
                            Moderators
                            wrote on last edited by
                            #21

                            @mpergand

                            Where do you think these two files go ?

                            the info.plist actually not in your app bundle, at least not the one you mark in that way. the app bundle contains the binary version of it, not the human readable one

                            I try to do the same things the Qt way with RESOURCES
                            RESOURCES +=$$files(img/*.jpg)
                            the folder appears in the left panel hierarchy tree, but it doesn't work because no qrc is created.

                            right click on your project -> add new -> Files and Classes - Qt -> Qt Resource File

                            than right click on the resource file -> add existing file/directory


                            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                            Q: What's that?
                            A: It's blue light.
                            Q: What does it do?
                            A: It turns blue.

                            1 Reply Last reply
                            2
                            • M Offline
                              M Offline
                              mpergand
                              wrote on last edited by
                              #22

                              @J-Hilk said in problem with paths (or QPainter):

                              the app bundle contains the binary version of it, not the human readable one

                              If I look at Preview app, info.plist is a text file, but not writable.
                              Maybe a extra process is needed to serialize the bundle ?

                              right click on your project -> add new -> Files and Classes - Qt -> Qt Resource File

                              than right click on the resource file -> add existing file/directory

                              Yes I know, I was asking for an automatic process with a qmake command.

                              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