6

I have hundreds of HTML files in my project, and I don't want to compile all of these HTML files into an .exe. Therefore I'd like to build my HTML files into a .dll file instead.

How can I embed such a Qt resource into a .dll file or other type of compiled library?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Reza Ebrahimi
  • 3,623
  • 2
  • 27
  • 41
  • What have you tried? This should be possible using Qt's standard resource embedding facilities (correct me if libraries are different from applications here, though I think I've used resources successfully with DLLs before), which you of course know how to use from [Qt's excellent documentation](http://qt-project.org/doc/qt-4.8/resources.html). – Christian Rau Jan 31 '13 at 19:37
  • As a general answer, while I don't know what happens when the names of multiple resources conflict, I have already successfully used an exe with its own Qt resources built into it, which loaded a dll that had another resource built into it and used it, without using any special means, just the Qt resource system for both the exe and the dll. That's why I'd like to hear where you encountered any particular problems. – Christian Rau Jan 31 '13 at 19:47
  • 2
    because when normaly compile qt project, resource file embed into exe file, my question is I want to embed them to dll file not exe, this is not clear Christian? – Reza Ebrahimi Jan 31 '13 at 19:51
  • @RezaEbrahimi Then just do a dll project instead of an exe, the Qt resource systems works the same. Have you tried it? If yes, then *what didn't work and how*? – Christian Rau Jan 31 '13 at 20:02
  • 2
    OK, things got a little out of hand here, so I've pruned the comments. Reza, you can't take downvotes personally, but you should use them as an indication that there might be something wrong with your question. Initially, it was lacking in information, which is why people voted against it. The additional details you provided helped significantly, although demanding that people provide code is usually considered rude here. I've tried to edit your question to clarify what you are asking, which should help to get better responses. – Brad Larson Jan 31 '13 at 21:25

2 Answers2

10

Are you going to use the dll only for the html files or is it going to contain code too? If the dll would be only for the html files, create an external external resource file instead.

Compile the qrc file to external resource file:

rcc -binary myresource.qrc -o myresource.rcc

Register the resource file in your exe:

QResource::registerResource("/path/to/myresource.rcc");
  • Is there a way to config this option in a .pro file? I mean calling rcc for specified files with -binary and -o option and calling QResource::registerResource for those files automatically? – Valentin H Aug 17 '15 at 05:56
2

If you are curious (or someone else needs this solution), I had same problem, except RCC file was not option to me (I needed to be in DLL file).

Here is topic I started and solved

Basically, in my library (DLL) project I had to:

  1. include qrc_RESOURCE_NAME.cpp file in library (DLL) project (in .pro file) - this is generated at compilation time, so you will most likely need to compile twice (1st (only qmake is enough) to generate that qrc_RESOURCE_NAME.cpp file, 2nd to compile with project)
  2. include that qrc_RESOURCE_NAME.cpp (directly or indirectly) in your application (EXE) project
  3. use normally protocol qrc:/// (or shorter :/) for loading your files

For more details, visit link I have posted.

DRAX
  • 30,559
  • 2
  • 26
  • 28
  • in the way you talk about that, I can't see any dll exportation, I think this way not produce any dll file, please clarify your answer, thanks. – Reza Ebrahimi May 11 '13 at 20:24
  • I have modified my answer. Sorry for confusion, those modifications apply to library project, not application. – DRAX May 12 '13 at 23:22