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

Using a text file as resource of the project

Scheduled Pinned Locked Moved Solved Mobile and Embedded
9 Posts 4 Posters 21.8k 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.
  • OliveiraNTO Offline
    OliveiraNTO Offline
    OliveiraNT
    wrote on 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
    0
    • OliveiraNTO OliveiraNT

      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 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
      • Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on 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
        • Pradeep KumarP Offline
          Pradeep KumarP Offline
          Pradeep Kumar
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • OliveiraNTO Offline
            OliveiraNTO Offline
            OliveiraNT
            wrote on 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" );

            mrjjM 1 Reply Last reply
            0
            • OliveiraNTO OliveiraNT

              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" );

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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.

              OliveiraNTO 1 Reply Last reply
              2
              • mrjjM mrjj

                @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.

                OliveiraNTO Offline
                OliveiraNTO Offline
                OliveiraNT
                wrote on last edited by OliveiraNT
                #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?

                mrjjM 1 Reply Last reply
                0
                • OliveiraNTO OliveiraNT

                  @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?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #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.

                  OliveiraNTO 1 Reply Last reply
                  3
                  • mrjjM mrjj

                    @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.

                    OliveiraNTO Offline
                    OliveiraNTO Offline
                    OliveiraNT
                    wrote on last edited by
                    #9

                    Ok thanks for your help!

                    1 Reply Last reply
                    2

                    • Login

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