<html><head></head><body>Hi Jean,<div><br></div><div><div><strong>
From:
</strong>
 
Nuno Santos <nunosantos@imaginando.pt>
<br>
<strong>
To:
</strong>
 
Jean-Michaël Celerier <jeanmichael.celerier@gmail.com>
<br>
<strong>
Cc:
</strong>
 
Qt Project MailingList <interest@qt-project.org>
<br>
<strong>
Sent:
 
</strong>
7/25/2018 12:59 PM
<br>
<strong>
Subject:
</strong>
 
Re: [Interest] App crashing because of ImageProvider when exiting
<br><br><blockquote class="mori" style="margin:0 0 0 .8ex;border-left:1px solid #CCC;padding-left:1ex;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="mcnt">Jean,<div class="mcnt"><br class="mcnt"></div><div class="mcnt">This is the main context. It will not get out until app.exec() terminates.</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">That’s why I’m connecting to aboutToQuit signal in order to remove the provider from the Qml engine. </div></div></blockquote></div></div><div><br></div><div>Since the engine takes ownership you don't need to remove the image provider in your case, since you're not adding/removing providers dynamically during runtime.</div><br><div><div><blockquote class="mori" style="margin:0 0 0 .8ex;border-left:1px solid #CCC;padding-left:1ex;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="mcnt"><div class="mcnt"></div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">I had the provider instantiated inside the controller but I was having this problem already, therefore my efforts in getting it fixed.</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt"><div class="mcnt"><b class="mcnt">QQmlApplicationEngine *e;</b></div><div class="mcnt"><b class="mcnt"><br class="mcnt"></b></div><div class="mcnt"><b class="mcnt">int main(int argc, char *argv[])</b></div><div class="mcnt"><b class="mcnt">{</b></div><div class="mcnt"><b class="mcnt">    QGuiApplication app(argc, argv);</b></div><div class="mcnt"><b class="mcnt"><br class="mcnt"></b></div><div class="mcnt"><b class="mcnt">    Controller controller;</b></div><div class="mcnt"><b class="mcnt"><br class="mcnt"></b></div><div class="mcnt"><b class="mcnt">    QQmlApplicationEngine engine;</b></div><div class="mcnt"><b class="mcnt"><br class="mcnt"></b></div><div class="mcnt"><b class="mcnt">    e = &engine;</b></div><div class="mcnt"><b class="mcnt"><br class="mcnt"></b></div><div class="mcnt"><b class="mcnt">    engine.rootContext()->setContextProperty("controller", &controller);</b></div><div class="mcnt"><b class="mcnt">    engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));</b></div><div class="mcnt"><b class="mcnt"><br class="mcnt"></b></div><div class="mcnt"><b class="mcnt">    ImageProvider imageProvider;</b></div><div class="mcnt"><b class="mcnt">    engine.addImageProvider("pictures", &imageProvider);</b></div><div class="mcnt"><b class="mcnt"><br class="mcnt"></b></div><div class="mcnt"><b class="mcnt">    QObject::connect(&app, &QGuiApplication::aboutToQuit, [=]()</b></div><div class="mcnt"><b class="mcnt">    {</b></div><div class="mcnt"><b class="mcnt">        e->removeImageProvider("pictures");</b></div><div class="mcnt"><b class="mcnt">    });</b></div><div class="mcnt"><b class="mcnt"><br class="mcnt"></b></div><div class="mcnt"><b class="mcnt">    return app.exec();</b></div><div class="mcnt"><b class="mcnt">}</b></div></div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">Any ideas?</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">Regards,</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">Nuno</div><div class="mcnt"><div><br class="mcnt"><blockquote type="cite" class="mcnt"><div class="mcnt">On 25 Jul 2018, at 11:30, Jean-Michaël Celerier <<a href="mailto:jeanmichael.celerier@gmail.com" class="mailto" title="Send email to jeanmichael.celerier@gmail.com" target="_blank">jeanmichael.celerier@gmail.com</a>> wrote:</div><br class="mcntApple-interchange-newline"><div class="mcnt"><div class="mcnt">Shouldn't you allocate your ImageProvider on the heap or at least ensure that it survives during the whole execution ? here it will be deleted by the end of your function<br class="mcnt"></div><div class="mcntgmail_extra"><br clear="all" class="mcnt"><div class="mcnt"><div class="mcntgmail_signature"><div class="mcnt"><div class="mcnt"><br class="mcnt"></div><div class="mcnt"><font color="#783f04" class="mcnt"><br class="mcnt"></font></div><div class="mcnt"><font face="arial, helvetica, sans-serif" size="2" color="#134f5c" class="mcnt">-------</font></div><font face="arial, helvetica, sans-serif" size="2" color="#134f5c" class="mcnt">Jean-Michaël Celerier</font><div class="mcnt"><font face="arial, helvetica, sans-serif" size="2" color="#134f5c" class="mcnt"><a href="http://www.jcelerier.name/" target="_blank" class="mcnt">http://www.jcelerier.name</a></font></div></div></div></div>
<br class="mcnt"><div class="mcntgmail_quote">On Wed, Jul 25, 2018 at 11:24 AM, Nuno Santos <span class="mcnt"><<a href="mailto:nunosantos@imaginando.pt" target="_blank" class="mailto" title="Send email to nunosantos@imaginando.pt">nunosantos@imaginando.pt</a>></span> wrote:<br class="mcnt"><blockquote class="mcntgmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class="mcnt">Hi,<div class="mcnt"><br class="mcnt"></div><div class="mcnt">Yesterday I have used for the first time a QQuickImageProvider but I’m having problems because now the app crashes when I terminate it.</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">Tried to do the following in order to avoid the crash but it is crashing anyway:</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt"><div class="mcnt">ImageProvider imageProvider;</div><div class="mcnt">engine.addImageProvider("pictures", &imageProvider);</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">QObject::connect(&app, &QGuiApplication::aboutToQuit, [=]()</div><div class="mcnt">{</div><div class="mcnt">    e->removeImageProvider("pictures");</div><div class="mcnt">});</div></div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">The crash is always something like this:</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt"><div style="margin:0px" class="mcnt"><span style="color:#aa0000" class="mcnt">malloc: *** error for object 0x7ffeef34e900: pointer being freed was not allocated</span></div></div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">Does anyone knows how to fix this?</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">Thanks!</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">Regards,</div><div class="mcnt"><br class="mcnt"></div><div class="mcnt">Nuno</div><div class="mcnt"><br class="mcnt"></div></div><br class="mcnt">_______________________________________________<br class="mcnt">
Interest mailing list<br class="mcnt">
<a href="mailto:Interest@qt-project.org" class="mailto" title="Send email to Interest@qt-project.org" target="_blank">Interest@qt-project.org</a><br class="mcnt">
<a href="http://lists.qt-project.org/mailman/listinfo/interest" target="_blank" class="mcnt">http://lists.qt-project.org/mailman/listinfo/interest</a><br class="mcnt">
<br class="mcnt"></blockquote></div><br class="mcnt"></div>
</div></blockquote></div><br class="mcnt"></div></div><br><br>_______________________________________________
<br>Interest mailing list
<br>Interest@qt-project.org
<br>http://lists.qt-project.org/mailman/listinfo/interest
<br></blockquote></div></div></body></html>