Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.12.0, 5.15.8, 6.2.2
-
-
f3d9e9214b (qt/qtdeclarative/dev) f3d9e9214b (qt/tqtc-qtdeclarative/dev) 45ba50f7bd (qt/qtdeclarative/6.4) 45ba50f7bd (qt/tqtc-qtdeclarative/6.4)
Description
QResource::unregisterResource() returns false if the resource is either not found, or if it is still in use by something.
I am trying to run a simple example where I dynamically load a red rectangle into the display, and unregister it from the resource system when the object is destroyed.
The code and rcc files are attached.
In the example that I wrote, you can register a resource, create the object, delete the object from the Loader QML type, and unregister the resource.
These are the steps to reproduce the bug:
- Click the load resource button
- Click the create button
- Click the Kill button
- Click the unregister button
With this logic, the resource should successfully be unregistered, but remains in memory, and the unregisterResource function returns false.
After the unregisterResource function returns false, the creating of the component for that QML file still works.
What is preventing QResource::unregisterResource() from completely removing this resource from memory?
A small working example that seems to have the same outcome each time:
QResource::registerResource(resourcePath, mapRoot); QQmlComponent *component = new QQmlComponent(engine_, pathInsideResource); component->deleteLater(); // wait til destruction QResource::unregisterResource(resourcePath, mapRoot);
If you don’t create the component (only register, unregister), unregister always returns true. if you create a component based on something inside the resource, it will always return false, regardless of if the component has been destroyed or not. This createComponent part can occur in C++ or QML and it has the same result