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. How to get the path of a .c file which is added as the Resource file
Forum Update on Monday, May 27th 2025

How to get the path of a .c file which is added as the Resource file

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
12 Posts 4 Posters 1.3k 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.
  • K Offline
    K Offline
    kabdul
    wrote on last edited by
    #1

    Hi,

    I am new to qt. I have created a sample project for accessing and reading the .c file. I have added the .c file in the resource file location but when I am trying to access the file I am unable to access the file. I have tried with below 3 methods but no use. Please help me to solve this. Below is the code which I am using for accessing the C File.

    //Method 1
    QString program("cmd.exe");
    QStringList parameters;
    parameters << " /k" << "gcc " << QUrl("qrc:/hex/hexFile/HV2.c").toString()<<" 1 " <<"test";
    QProcess::startDetached(program, parameters);

    //Method 2

    QProcess process2;
    process2.start("gcc", QStringList() << QUrl("qrc:/hex/hexFile/HV2.c").toString()<<" 1 " <<"test";

    //method 3

    QProcess process3;
    process3.start("gcc", QStringList() << ":/hex/hexFile/HV2.c"<<" 1 " <<"test";

    I am trying to execute the c file with two parameters "1" and "test" but it is not success.

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

      Hi,

      Qt resources are not accessible to outside application like you are trying to do. If you want to compile that file you first have to copy the resource to a known location and then you can pass it to gcc to build.

      Note that this is a pretty strange idea. Why do you want to build a c file embedded in your application ?

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

      K 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Qt resources are not accessible to outside application like you are trying to do. If you want to compile that file you first have to copy the resource to a known location and then you can pass it to gcc to build.

        Note that this is a pretty strange idea. Why do you want to build a c file embedded in your application ?

        K Offline
        K Offline
        kabdul
        wrote on last edited by
        #3

        @SGaist said in How to get the path of a .c file which is added as the Resource file:

        ccessible to outside application like you are trying to d

        Hi,

        My Idea is I am having a Android device. I am creating the android app in QT for browsing the files in the device and while selecting the file I need to call the c file which is having two argument(one is the selected file). I don't know how to do this. I need to show the demo to my Manager regarding this. Can you please help me with some sample code for doing this.

        JonBJ 1 Reply Last reply
        0
        • K kabdul

          @SGaist said in How to get the path of a .c file which is added as the Resource file:

          ccessible to outside application like you are trying to d

          Hi,

          My Idea is I am having a Android device. I am creating the android app in QT for browsing the files in the device and while selecting the file I need to call the c file which is having two argument(one is the selected file). I don't know how to do this. I need to show the demo to my Manager regarding this. Can you please help me with some sample code for doing this.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @kabdul said in How to get the path of a .c file which is added as the Resource file:

          I need to call the c file which is having two argument(one is the selected file)

          .c files are text files, you can't execute them. I have a feeling you might be talking about compiling an executable from a .c source file, and then executing that as a sub-process?

          You can'r show a demo to your manager without some clear idea of what is going on.

          K 1 Reply Last reply
          0
          • JonBJ JonB

            @kabdul said in How to get the path of a .c file which is added as the Resource file:

            I need to call the c file which is having two argument(one is the selected file)

            .c files are text files, you can't execute them. I have a feeling you might be talking about compiling an executable from a .c source file, and then executing that as a sub-process?

            You can'r show a demo to your manager without some clear idea of what is going on.

            K Offline
            K Offline
            kabdul
            wrote on last edited by
            #5

            @JonB Thank you for your reply. Is it possible to execute a .bin file using the QProcess.

            JonBJ 1 Reply Last reply
            0
            • K kabdul

              @JonB Thank you for your reply. Is it possible to execute a .bin file using the QProcess.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #6

              @kabdul
              I am not an Android expert/programmer. If the .bin file is an executable file, then in principle, yes, you can use QProcess to execute it as a sub-process. This sounds to me more like what you are wanting to achieve.

              The gcc command you show is for compiling a .c file. You get some executable from that, and that is what you run, passing your arguments. You seem to be confusing those two steps.

              K 2 Replies Last reply
              1
              • JonBJ JonB

                @kabdul
                I am not an Android expert/programmer. If the .bin file is an executable file, then in principle, yes, you can use QProcess to execute it as a sub-process. This sounds to me more like what you are wanting to achieve.

                The gcc command you show is for compiling a .c file. You get some executable from that, and that is what you run, passing your arguments. You seem to be confusing those two steps.

                K Offline
                K Offline
                kabdul
                wrote on last edited by
                #7

                @JonB How to do that can you please share any sample code for this. I am trying this for more than 2 weeks still now I didn't get any solution for this. Please help me on this.

                1 Reply Last reply
                0
                • JonBJ JonB

                  @kabdul
                  I am not an Android expert/programmer. If the .bin file is an executable file, then in principle, yes, you can use QProcess to execute it as a sub-process. This sounds to me more like what you are wanting to achieve.

                  The gcc command you show is for compiling a .c file. You get some executable from that, and that is what you run, passing your arguments. You seem to be confusing those two steps.

                  K Offline
                  K Offline
                  kabdul
                  wrote on last edited by
                  #8

                  @JonB How to run this bin file. Which I have added in the resource file. Is there any way to access this bin file. And can you please share me some sample code to execute this bin file with some arguments using QProcess. If you share some code it will be big help for me.

                  JonBJ 1 Reply Last reply
                  0
                  • K kabdul

                    @JonB How to run this bin file. Which I have added in the resource file. Is there any way to access this bin file. And can you please share me some sample code to execute this bin file with some arguments using QProcess. If you share some code it will be big help for me.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #9

                    @kabdul
                    You cannot run/execute a file while it is in a Qt resource. It is your job to write code, using QFile to access the resource path, to extract and copy it to an external file somewhere, and then execute that, assuming Android allows that.

                    Then

                    qDebug() << QProcess::execute("/path/to/extracted/file.bin", QStringList() << "1" << "test");
                    

                    would be a start.

                    K 1 Reply Last reply
                    2
                    • JonBJ JonB

                      @kabdul
                      You cannot run/execute a file while it is in a Qt resource. It is your job to write code, using QFile to access the resource path, to extract and copy it to an external file somewhere, and then execute that, assuming Android allows that.

                      Then

                      qDebug() << QProcess::execute("/path/to/extracted/file.bin", QStringList() << "1" << "test");
                      

                      would be a start.

                      K Offline
                      K Offline
                      kabdul
                      wrote on last edited by
                      #10

                      @JonB said in How to get the path of a .c file which is added as the Resource file:

                      You cannot run/execute a file while it is in a Qt resource. It is your job to write code, using QFile to access the resource path, to copy it to an external file somewhere, and then execute it, assuming Android allows that.
                      Then
                      qDebug() << QProcess::execute("/path/to/extracted/file.bin", QStringList() << "1" << "test");

                      would be a start.

                      Thank You very much for your kindly help. I will try this code and get back to you if I need any help.

                      1 Reply Last reply
                      0
                      • KH-219DesignK Offline
                        KH-219DesignK Offline
                        KH-219Design
                        wrote on last edited by KH-219Design
                        #11

                        To strictly address the bare title of this thread, here is code showing how to create an on-disk path for a file from the QRC resources, and then read that file from disk:

                          // note the ":" at the front of the path
                          std::string path_inside_qrc = ":/data/sim_rpc_replies_immediate_scores.pbtxt";
                          std::unique_ptr<QTemporaryFile> temporary_file;
                        
                          temporary_file.reset(
                                QTemporaryFile::createNativeFile(QString::fromStdString(path_inside_qrc))
                          );
                          std::string file_name = temporary_file->fileName().toUtf8().constData();
                          
                          // TODO: add code to use the temporary file.
                         
                          // Delete the temp file after using it
                          temporary_file.reset();
                        

                        This thread caught my eye because once upon a time it took me an hour or two to figure out that the above code solves that problem.

                        However, having said that...

                        Like everyone else who has responded here, it seems extremely unlikely that invoking gcc from a QProcess on Android is going to bring anyone a firm solution to anything in the end.

                        Unless your Android device is comprehensively rooted, I'm 99% sure that the system will not allow your application or service to invoke a compiler. And even if your device is rooted, this seems like a highly advanced topic for someone who appears to be new at Qt, new at Android, and new at gcc. I'm reasonably versed in all 3, and I would not for a minute volunteer to attempt this. (At least, I would require a lot of well-reasoned rationale to be presented first.)

                        www.219design.com
                        Software | Electrical | Mechanical | Product Design

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

                          @KH-219Design said in How to get the path of a .c file which is added as the Resource file:

                          Like everyone else who has responded here, it seems extremely unlikely that invoking gcc from a QProcess on Android is going to bring anyone a firm solution to anything in the end.

                          Which reminds me that they have switched to clang if memory serves well.

                          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
                          0

                          • Login

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