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. Resource path for non-qt functions
Forum Updated to NodeBB v4.3 + New Features

Resource path for non-qt functions

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 6 Posters 4.3k Views 3 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.
  • J JonB
    11 Aug 2020, 22:16

    @Engelard
    I have explained, I don't know how to explain it any clearer.

    If you ship a resource, it isn't an external file, you can't pass it to OpenCV anything.

    A resource is addressed via :/... path. That is not a real file. The only thing that can open it is QFile.

    Use that to open its content for read. Read its whole content, writing that to a real, external file. [EDIT @SimonSchroeder shows later on that you can simply use QFile::copy() to do this in one line.] Pass the path of that extracted file to your external OpenCV.

    If you don't understand this, you can't use a resource file for your purpose of passing it to OpenCV. In that case give up on resources and supply the file as an external file, not a resource.

    E Offline
    E Offline
    Engelard
    wrote on 11 Aug 2020, 23:03 last edited by
    #21

    @JonB said in Resource path for non-qt functions:

    Read its whole content, writing that to a real, external file.

    you mean - make a copy of that file from resources? Even if i'll do that, i should create folder for that .jpg file, so it would'nt be messy, and then i should delete that copy when my program is about to be closed. Am i right?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Engelard
      wrote on 11 Aug 2020, 23:54 last edited by
      #22

      Problem "resolved". From this topic i understand that i can't acces .res files of my qt app, it's okay. But then i found that i'm not able to simply use relative path's in my app for some strange qt reason.

      So i found such wonderful static function - QString QCoreApplication::applicationDirPath(); which returns directory of running app, then simply add desired "relative" path QString and here we go!

      J 1 Reply Last reply 12 Aug 2020, 07:35
      0
      • B Offline
        B Offline
        Bonnie
        wrote on 11 Aug 2020, 23:55 last edited by Bonnie 8 Dec 2020, 00:06
        #23

        What OpenCV functions are you planning to use with the image files?
        If you only use cv::imread you can try to replace that with QFile + cv::imdecode or create a cv::Mat directly from a QImage.

        E 1 Reply Last reply 12 Aug 2020, 00:08
        2
        • B Bonnie
          11 Aug 2020, 23:55

          What OpenCV functions are you planning to use with the image files?
          If you only use cv::imread you can try to replace that with QFile + cv::imdecode or create a cv::Mat directly from a QImage.

          E Offline
          E Offline
          Engelard
          wrote on 12 Aug 2020, 00:08 last edited by Engelard 8 Dec 2020, 00:20
          #24

          @Bonnie said in Resource path for non-qt functions:

          or create a cv::Mat directly from a QImage.

          Tnx. I just started with OpenCV, by now need exactly Mat creation. Which one is better for performance? From QFile or from QImage?

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Engelard
            wrote on 12 Aug 2020, 00:35 last edited by
            #25

            Bonnie, you just saved the day. Because of your hint i found this golden answer work of art: https://stackoverflow.com/a/33923407 Everything tested and well explained, conversion from QFile as he mentioned 10 times faster then from QImage.

            1 Reply Last reply
            1
            • E Engelard
              11 Aug 2020, 23:54

              Problem "resolved". From this topic i understand that i can't acces .res files of my qt app, it's okay. But then i found that i'm not able to simply use relative path's in my app for some strange qt reason.

              So i found such wonderful static function - QString QCoreApplication::applicationDirPath(); which returns directory of running app, then simply add desired "relative" path QString and here we go!

              J Offline
              J Offline
              JonB
              wrote on 12 Aug 2020, 07:35 last edited by
              #26

              @Engelard said in Resource path for non-qt functions:

              So i found such wonderful static function - QString QCoreApplication::applicationDirPath(); which returns directory of running app, then simply add desired "relative" path QString and here we go!

              Which is why I wrote to you earlier on:

              When you open files at runtime you would be best making a full path to them. If you plan to pass this path to an external program, you may be advised to pass the full path. There are Qt methods to provide strings for the path, e.g. https://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath.

              E 1 Reply Last reply 12 Aug 2020, 12:53
              1
              • J JonB
                12 Aug 2020, 07:35

                @Engelard said in Resource path for non-qt functions:

                So i found such wonderful static function - QString QCoreApplication::applicationDirPath(); which returns directory of running app, then simply add desired "relative" path QString and here we go!

                Which is why I wrote to you earlier on:

                When you open files at runtime you would be best making a full path to them. If you plan to pass this path to an external program, you may be advised to pass the full path. There are Qt methods to provide strings for the path, e.g. https://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath.

                E Offline
                E Offline
                Engelard
                wrote on 12 Aug 2020, 12:53 last edited by
                #27

                @JonB said in Resource path for non-qt functions:

                Which is why I wrote to you earlier on:

                Yeah, back then i did'nt give it serious attention, was thinking that using relative path's it is the only right way for program to use it's own files.

                J 1 Reply Last reply 12 Aug 2020, 12:54
                0
                • E Engelard
                  12 Aug 2020, 12:53

                  @JonB said in Resource path for non-qt functions:

                  Which is why I wrote to you earlier on:

                  Yeah, back then i did'nt give it serious attention, was thinking that using relative path's it is the only right way for program to use it's own files.

                  J Offline
                  J Offline
                  JonB
                  wrote on 12 Aug 2020, 12:54 last edited by JonB 8 Dec 2020, 12:57
                  #28

                  @Engelard said in Resource path for non-qt functions:

                  Yeah, back then i did'nt give it serious attention

                  Yeah, that's nice to hear ;-) I'll bear it mind for my future replies to you :D :D [<-- For the avoidance of any misinterpretations: winks/smileys!]

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    SimonSchroeder
                    wrote on 13 Aug 2020, 07:09 last edited by
                    #29

                    @Engelard One thing to consider – as you have mentioned that OpenCV might also be writing (to) files – is that if you distribute your app and people install it properly they might not be able to write into the applications folder. Usually, these folders are only writeable for administrators/root. Have a look at https://doc.qt.io/qt-5/qstandardpaths.html to figure out where to put which kind of files. Furthermore, there is QTemporaryDir and QTemporaryFile if the data is supposed to only exist until you close your software.

                    BTW: If you provide something inside your resources and need to have a copy inside the real filesystem, a simple QFile::copy(":files/lego.jpg", "/some/tmp/path/files/lego.jpg") is sufficient. You don't need to open the file and read it in. (Though your solution you found on StackOverflow is also valid.)

                    1 Reply Last reply
                    3

                    21/29

                    11 Aug 2020, 23:03

                    • Login

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