How do I split out QML files embedded within a DLL?

271 Views Asked by At

I have QML file that has been embedded into a dll. I think it was done something like this

How can I embed a Qt resource into a .dll file? (The second answer).

Is there anyway to split out the QML file to obtain the source code? I am not very familiar with QT framework

1

There are 1 best solutions below

0
Ivan Belyaev On

If it's embedded via *.qrc, then it's NOT compatible with standard windows/linux (.dll/.so) resource formats. qrc is compiled as xxx_qrc.cpp file and embedded by linker as .obj file with static initialization code. I.e. it's just part of the binary. You can access "contents" of qrc via QFile with "qrc:/." URL. But for that, you have to load DLL with resources embedded in current process, because qrc is hooked up in static initialization (aka DllMain in Windows). Something like:

QLibrary lib("./library.dll");
if (!lib.load()) 
    throw exception(lib.errorString().toStdString());
QFile resource(":/resource.qml");
if (!resource.open(QIODevice::ReadOnly))
    throw exception(resource.errorString().toStdString());
resource.copy("./exported.qml");

To explore currently loaded virtual qrc file system tree, you can use QDir(":/"). I guess it's pretty easy to figure out the rest from here.

And of course - you have to be aware what sort of DLLs you are loading into your process, as they may contain arbitrary code that will be executed as you call QLibrary::load!