As part of a Qt Designer hacking, I'm interested in removing a resource in runtime (specifically :/trolltech/widgetbox/widgetbox.xml
). Refer to the end of the post for more detail about the context.
My obvious (and failed) attempt was:
QFile(":/trolltech/widgetbox/widgetbox.xml").remove();
but it returned an error.
My next attempt was to use Q_CLEANUP_RESOURCE(widgetbox)
, but the functions it expands to are only available within a private component of Qt Designer (QDesignerComponents).
Another attempt was to clear the content of the file, but it is read-only:
QFile f(":/trolltech/widgetbox/widgetbox.xml");
if (f.open(QFile::WriteOnly)) { ... } // returns false
I've also tried to overwrite it in the Qt resource's filesystem by defining my own :/trolltech/widgetbox/widgetbox.xml
. I'm able to open the file but it fails to retrieve data, I guess because it is a duplicate resource (aliasing the resource to an unused name makes the application to print out the content correctly). On the other hand, the list of widgets is presented correctly.
QFile f(":/trolltech/widgetbox/widgetbox.xml");
if (f.open(QFile::ReadOnly)) {
qDebug() << "{";
qDebug() << f.readAll(); // shows nothing
qDebug() << "}";
}
Is there any way to modify/remove/replace a resource file in runtime?
In the case you consider this an XY problem I'll explain the whole context: I'm integrating Qt Designer into my own IDE by making small tweaks to the standalone one. Basically, I've added a compilation flag to generate a dynamic library instead of an executable, and added some options to expose the main window.
In this IDE I want to add an option to avoid the user to use the default widgets and restrict the list to a set of custom ones. The resource I mention is the file containing the list of widgets available in Qt Designer by default. Additional widgets can be easily included via plugins, but I haven't found a way to remove default ones.
One option I have is to make that load optional, but it will produce a cascade of changes through many projects. I'd like to avoid modifying Qt Designer so much.