Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to import an execution file into a Qt application?



  • I have an execution file.
    I want to import/attach/include,...(I don't know exactly) this file to project.
    After build. I have a Qt application.
    The first run Qt app, the an execution file export to path of Qt app.
    How to do this?


  • Moderators

    @Kien-Bui
    even this isn't by far not very nice, but since u asked for:

    put the executable into a qrc file and write it out:

    QFile in(":/my/executable");
    in.open( QFile::ReadOnly );
    
    QFile out( QCoreApplication::applicationDirPath() % QString("/executableName") ); // next to the application executable
    out.open( QFile::WriteOnly );
    
    out.write( in.readAll() );
    out.close();
    in.close();
    

    But you are advised to better distribute it along with your application, instead of embedding it with qrc.



  • @raven-worx said in How to import an execution file into a Qt application?:

    But you are advised to better distribute it along with your application, instead of embedding it with qrc.

    Because my Qt app need exec a process with that file. Another way is compressed two files into a zip file.
    I don't have better solution for this.



  • @Kien-Bui

    Because my Qt app need exec a process with that file.

    Don't understand what the relevance of that is. @raven-worx is suggesting that distributing the executable(s) as separate files is a better idea than embedding them into your executable with qrc and extracting them. And I agree with him. The fact that you will need to "exec a process with that file" has no bearing on how you distribute it, separately or embedded.



  • @JonB seperate. OK I will try with qrc. Tks


  • Lifetime Qt Champion

    @Kien-Bui
    Just as note. embedding it and save to file to execute them might trigger a
    heuristics scanner the user might be using. (Avast does)
    Might not be issue in your case, but just be aware of it. :)


Log in to reply