Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Using a text file as resource of the project
Forum Updated to NodeBB v4.3 + New Features

Using a text file as resource of the project

Scheduled Pinned Locked Moved Solved Mobile and Embedded
9 Posts 4 Posters 21.9k 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.
  • O Offline
    O Offline
    OliveiraNT
    wrote on 3 Nov 2016, 17:58 last edited by
    #1

    I'm trying to access a text file using a function in c++ to read this but I don't know how access this text file.
    The text file are in the project folder and was added into the project as a resource. I already tryed put the full url using the prefix but still not working.

    the .qrc file

    <RCC>
        <qresource prefix="/NN">
            <file alias="dumped">dumped.nnet</file>
        </qresource>
    </RCC>
    

    P.S. I'm trying this on a Android project.

    K 1 Reply Last reply 3 Nov 2016, 18:04
    0
    • O OliveiraNT
      3 Nov 2016, 17:58

      I'm trying to access a text file using a function in c++ to read this but I don't know how access this text file.
      The text file are in the project folder and was added into the project as a resource. I already tryed put the full url using the prefix but still not working.

      the .qrc file

      <RCC>
          <qresource prefix="/NN">
              <file alias="dumped">dumped.nnet</file>
          </qresource>
      </RCC>
      

      P.S. I'm trying this on a Android project.

      K Offline
      K Offline
      koahnig
      wrote on 3 Nov 2016, 18:04 last edited by
      #2

      @OliveiraNT

      Did you check out QFile as in the example here ?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      2
      • P Offline
        P Offline
        Pradeep Kumar
        wrote on 3 Nov 2016, 18:23 last edited by
        #3

        Hi,

        Sample code for fetching the data from resource file
        I have used prefix and added sampleText.txt

        Then using QFile class to read the data from the text file.

        void RessourceFile::getData()
        {

        QString data;
        QString fileName(":/new/prefix1/sampleText.txt");
        
        QFile file(fileName);
        if(!file.open(QIODevice::ReadOnly)) {
            qDebug()<<"filenot opened"<<endl;
        }
        else
        {
            qDebug()<<"file opened"<<endl;
            data = file.readAll();
        }
        
        file.close();
        
        qDebug()<<data<<endl;
        

        }

        Which worked in Desktop and android platforms.
        Hope this helps you.

        Thanks,

        1 Reply Last reply
        5
        • P Offline
          P Offline
          Pradeep Kumar
          wrote on 3 Nov 2016, 18:27 last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • O Offline
            O Offline
            OliveiraNT
            wrote on 4 Nov 2016, 16:29 last edited by
            #5

            I already have a function to read the file and its works but only when I put the file directly into the memory by usb and pass the path to the function. What I need is a way to do this using the file inside the project but when I try pass to the function this :
            ":/NN/dumped"
            the function can't find the file.

            my funcion:

            Works
            keras::KerasModel m("/sdcard/Documents/dumped.nnet");

            Don't work
            keras::KerasModel m(":/NN/dumped" );

            M 1 Reply Last reply 4 Nov 2016, 16:34
            0
            • O OliveiraNT
              4 Nov 2016, 16:29

              I already have a function to read the file and its works but only when I put the file directly into the memory by usb and pass the path to the function. What I need is a way to do this using the file inside the project but when I try pass to the function this :
              ":/NN/dumped"
              the function can't find the file.

              my funcion:

              Works
              keras::KerasModel m("/sdcard/Documents/dumped.nnet");

              Don't work
              keras::KerasModel m(":/NN/dumped" );

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 4 Nov 2016, 16:34 last edited by
              #6

              @OliveiraNT
              Hi
              Inside KerasModel where you try to read the file, do you use
              QFile to read it?
              Other file function ( std c++) do not understand ":/" syntax.

              O 1 Reply Last reply 4 Nov 2016, 16:40
              2
              • M mrjj
                4 Nov 2016, 16:34

                @OliveiraNT
                Hi
                Inside KerasModel where you try to read the file, do you use
                QFile to read it?
                Other file function ( std c++) do not understand ":/" syntax.

                O Offline
                O Offline
                OliveiraNT
                wrote on 4 Nov 2016, 16:40 last edited by OliveiraNT 11 Apr 2016, 16:40
                #7

                @mrjj No, I'not using QFile is a std function.
                Is there any way to do this in std or I have to change to QFile?

                M 1 Reply Last reply 4 Nov 2016, 16:41
                0
                • O OliveiraNT
                  4 Nov 2016, 16:40

                  @mrjj No, I'not using QFile is a std function.
                  Is there any way to do this in std or I have to change to QFile?

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 4 Nov 2016, 16:41 last edited by mrjj 11 Apr 2016, 16:41
                  #8

                  @OliveiraNT
                  You must use QFile.
                  the text file is actually embedded into the exe file and only
                  QFile can read it from there.
                  Other file classes simply do not know about resources and hence QFile must be used.

                  O 1 Reply Last reply 4 Nov 2016, 16:41
                  3
                  • M mrjj
                    4 Nov 2016, 16:41

                    @OliveiraNT
                    You must use QFile.
                    the text file is actually embedded into the exe file and only
                    QFile can read it from there.
                    Other file classes simply do not know about resources and hence QFile must be used.

                    O Offline
                    O Offline
                    OliveiraNT
                    wrote on 4 Nov 2016, 16:41 last edited by
                    #9

                    Ok thanks for your help!

                    1 Reply Last reply
                    2

                    1/9

                    3 Nov 2016, 17:58

                    • 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