<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[SOLVED] Access to custom widget&#x27;s object after dynamic Ui loading]]></title><description><![CDATA[<p dir="auto">I've created a custom widget plugin for Qt Designer. Then i put this widget on a form and saved as a "widget.ui" file.<br />
In the main application:<br />
@<br />
QUiLoader loader;<br />
QFile file("widget.ui");<br />
file.open(QFile::ReadOnly);<br />
QWidget *myWidget = loader.load(&amp;file, 0);<br />
file.close();<br />
@</p>
<p dir="auto">This custom widget can be shown after that . But i need to access some his methods. Is there a way to do that?<br />
I'm trying to get him by:<br />
@myWidget-&gt;findChild&lt;CustomWidgetClass*&gt;();@</p>
<p dir="auto">It has no effect. Null pointer was returned.</p>
]]></description><link>https://forum.qt.io/topic/16252/solved-access-to-custom-widget-s-object-after-dynamic-ui-loading</link><generator>RSS for Node</generator><lastBuildDate>Sun, 20 Sep 2026 19:49:15 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/16252.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 27 Apr 2012 13:55:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] Access to custom widget&#x27;s object after dynamic Ui loading on Sat, 28 Apr 2012 08:28:55 GMT]]></title><description><![CDATA[<p dir="auto">Thank you for your answer! I think i found a solution.<br />
Back to reality:</p>
<ol>
<li>I've created a class PushButton - successor of QPushButton. Implementation of this widget was made in plugin for Qt Designer.</li>
<li>In Qt Designer i've selected QDockWidget like a container-form.</li>
<li>PushButton was placed on the form.</li>
<li>Form was saved in "widget.ui" file.</li>
<li>In main application dock widget is loading by<br />
@QWidget *myWidget = loader.load(&amp;file, 0);@</li>
</ol>
<p dir="auto">with a qobject_cast 'ing.</p>
<ol start="6">
<li>Then i've tried to find my custom widget like a child of QDockWidget:<br />
@ myWidget-&gt;findChild&lt;PushButton*&gt;();@</li>
</ol>
<p dir="auto">but this method returned a NULL-pointer. Nevertheless, i can get target pointer by:</p>
<p dir="auto">@QPushButton <em>ancestor =  myWidget-&gt;findChild&lt;QPushButton</em>&gt;();@</p>
<p dir="auto">Object's casting from QPushButton to PushButton returned NULL also.</p>
<p dir="auto">My solution is:<br />
@if(ancestor-&gt;inherits("PushButton"))<br />
PushButton <em>btn = reinterpret_cast&lt;PushButton</em>&gt;(ancestor);<br />
@</p>
]]></description><link>https://forum.qt.io/post/137325</link><guid isPermaLink="true">https://forum.qt.io/post/137325</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sat, 28 Apr 2012 08:28:55 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Access to custom widget&#x27;s object after dynamic Ui loading on Fri, 27 Apr 2012 15:07:29 GMT]]></title><description><![CDATA[<p dir="auto">Have you tried:<br />
@<br />
CustomWidgetClasss <em>myWidget = qobject_cast&lt;CustomWidgetClass</em>&gt;(loader.load(&amp;file, 0));<br />
@</p>
]]></description><link>https://forum.qt.io/post/137266</link><guid isPermaLink="true">https://forum.qt.io/post/137266</guid><dc:creator><![CDATA[mlong]]></dc:creator><pubDate>Fri, 27 Apr 2012 15:07:29 GMT</pubDate></item></channel></rss>