Search code examples
qtqtwebkit

Qt including resource directory structure inside executable


I'm using QWebView to run a web app. There are 650+ files. Placing the web app's directory in the source directory does not result in the executable bundling the directory.

How do I include the entire web app directory so that the executable will be able to render the files.

Note: I have currently added index.html as a resource, and can access it with qrc:// - But since I cannot add the entire directory structure to a qrc (can I?), the executable does not include the other files.


Solution

  • You need to put an XML node into the .qrc file for each file you want to use using the Qt resource system.

    This can be done using a simple pre-build script. Take a look at qrcgen. Quoting the blog post behind this link:

    The script I created, qrcgen, takes a directory and a prefix, recursively scans the directory and generates a .qrc file with the same name as the directory scanned. It has solved my problem, and I hope it can help others. It is also available via PyPI, just "easy_install qrcgen".


    In order to update the .qrc file whenever your directory contens change, you need to include this step into your build process:

    • For C++/Qt projects, you can add this step in the build configuration in QtCreator or add in your qmake file a system(...) statement. Note that such commands aren't portable in general. (If it's not portable, you can put some operating system conditions around multiple commands.)

    • For PyQt/PySide projects, I don't know how to do this, but I'm sure you find a solution for this too.