I have a class that inherits QQuickItem
and QQuickImageProvider
. This class is instantiated from qml. I need to call QQmlEngine::addImageProvider
so that this class can actually provide images. I should be able to get the engine that my object exists in as described in this question. In the constructor of my class I'm calling
QQmlEngine *engine = nullptr;
QQmlContext *context = QQmlEngine::contextForObject(this);
if (context)
engine = context->engine();
if (engine)
engine->addImageProvider("MyImageProvider", this);
But QQmlEngine::contextForObject(this);
always returns a null pointer. Why does this not work?