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. Reading files from resources
QtWS25 Last Chance

Reading files from resources

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 728 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!

    I am trying to load a template from resources make a docx file (using docx factory lib). If I copy the template in the program folder, it reads successfully but, when I try to read it from resources, it can't read it.

    I have the same problem when I try to add an image in this docx. Is it possible to read this kind of files from the resources?

    /** TEMPLATE **/
    QString sTemplatePath = QApplication::applicationDirPath() + "/template.dfw";    // works fine
    QString sTemplatePath = ":/templates/resources/templates/template.dfw" // can't read the file
    
    l_merger.load(sTemplatePath.toStdString());
    
    ...
    
    /** IMAGES **/
    sImagePath = QCoreApplication::applicationDirPath() + "/image.png";   // works fine
    sImagePath = ":/images/resources/images/image.png";  // can't read the file
    
    l_merger.setClipboardValue("Header", "Image", sImagePath.toStdString());
    l_merger.paste("Header");
    ...
    

    Thank you very much!

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

      Hi,

      Do you have that folder structure in your resources ?

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

      1 Reply Last reply
      1
      • ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        Yes, when I want to use this images for example in the stylesheet it works fine.

        mrjjM 1 Reply Last reply
        0
        • ivanicyI ivanicy

          Yes, when I want to use this images for example in the stylesheet it works fine.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @ivanicy
          Hi
          And you find the DFW file in the explorer tree under ressources
          and right click and take path via menu so you are 10000% sure its correct path ?

          1 Reply Last reply
          1
          • ivanicyI Offline
            ivanicyI Offline
            ivanicy
            wrote on last edited by
            #5

            I took this path rightclicking on the resources file and selecting "Copy Path" option so the path is correct. I try with the "Copy URL" option too but with the same result.

            If I set a QPushButton icon with this paths, it works.

            mrjjM 1 Reply Last reply
            0
            • ivanicyI ivanicy

              I took this path rightclicking on the resources file and selecting "Copy Path" option so the path is correct. I try with the "Copy URL" option too but with the same result.

              If I set a QPushButton icon with this paths, it works.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @ivanicy
              But are you pasting it directly to the clipboard ?
              So when other app reads/see it,
              it will be the resource path which only a Qt app can understand ?

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

                See this:

                @ivanicy said in Reading files from resources:

                l_merger.load(sTemplatePath.toStdString());

                Looks like l_merger is not a Qt class, is it ? If so, then it won't be able to read from the resources because it has not idea on how to access it.

                In that case, you should create a temporary file, pass the path l_merger and continue processing.

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

                ivanicyI 1 Reply Last reply
                3
                • SGaistS SGaist

                  See this:

                  @ivanicy said in Reading files from resources:

                  l_merger.load(sTemplatePath.toStdString());

                  Looks like l_merger is not a Qt class, is it ? If so, then it won't be able to read from the resources because it has not idea on how to access it.

                  In that case, you should create a temporary file, pass the path l_merger and continue processing.

                  ivanicyI Offline
                  ivanicyI Offline
                  ivanicy
                  wrote on last edited by
                  #8

                  @SGaist Yes, I think this could be the problem. It is a third party library so, maybe what is happening herer is what you say. I get the same error trying to use this image with opencv.

                  mrjjM 1 Reply Last reply
                  0
                  • ivanicyI ivanicy

                    @SGaist Yes, I think this could be the problem. It is a third party library so, maybe what is happening herer is what you say. I get the same error trying to use this image with opencv.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @ivanicy
                    Hi
                    Yes, only QFile understands resources so if openCV uses normal file functions , it cannot load it.
                    You have to save to a real file first then and use that path.

                    ivanicyI 1 Reply Last reply
                    4
                    • mrjjM mrjj

                      @ivanicy
                      Hi
                      Yes, only QFile understands resources so if openCV uses normal file functions , it cannot load it.
                      You have to save to a real file first then and use that path.

                      ivanicyI Offline
                      ivanicyI Offline
                      ivanicy
                      wrote on last edited by
                      #10

                      @mrjj @SGaist Thank you both of you!

                      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