<?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[Is it recommended to include each widget explicitly?]]></title><description><![CDATA[<p dir="auto">This might be about a practice, but I want to know how experts consider this issue.<br />
Basically, all the base widgets are included together if I include a derived widget (for example, QFrame and QWidget are included together if I include QLabel)<br />
And there is an example like below.<br />
If included QWidget-derived widgets are used only in the findChild syntaxes,</p>
<pre><code>this-&gt;findChild&lt;QLineEdit*&gt;("blahblah");
this-&gt;findChild&lt;QLabel*&gt;("blahblah2");
this-&gt;findChild&lt;QPushButton*&gt;("blahblah3");
</code></pre>
<p dir="auto">They all can be replaced with</p>
<pre><code>this-&gt;findChild&lt;QWidget*&gt;("blahblah");
this-&gt;findChild&lt;QWidget*&gt;("blahblah2");
this-&gt;findChild&lt;QWidget*&gt;("blahblah3");
</code></pre>
<p dir="auto">In this case, including all the QLineEdit, QLabel, QPushButton is redundant.</p>
<p dir="auto">On the contrary, if QLabel header was already included and if I have to find a QWidget like below,</p>
<pre><code>this-&gt;findChild&lt;QWidget*&gt;("blahblah");
</code></pre>
<p dir="auto">There is no need to include QWidget because it was included already when QLabel was included.</p>
<p dir="auto">As far as I know, there is no performance issue for this, but I want to know what would be a better practice.</p>
]]></description><link>https://forum.qt.io/topic/93357/is-it-recommended-to-include-each-widget-explicitly</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 08:20:53 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/93357.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 04 Aug 2018 13:52:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is it recommended to include each widget explicitly? on Tue, 07 Aug 2018 04:29:20 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for everyone  for reply! I thought that forward declaration of QWidget-based headers is not a good practice, but I was wrong.</p>
]]></description><link>https://forum.qt.io/post/474347</link><guid isPermaLink="true">https://forum.qt.io/post/474347</guid><dc:creator><![CDATA[Aaron Kim]]></dc:creator><pubDate>Tue, 07 Aug 2018 04:29:20 GMT</pubDate></item><item><title><![CDATA[Reply to Is it recommended to include each widget explicitly? on Tue, 07 Aug 2018 00:10:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/buckwheat">@<bdi>Buckwheat</bdi></a> I do the same thing.  Forward declarations and only including exactly what I need.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aaron-kim">@<bdi>Aaron-Kim</bdi></a> Implicit declarations are bound to happen unfortunately.  And they do indeed cause issues when they are changed in the code that is including them.  I have had to deal with these problems numerous times.</p>
<p dir="auto">Plan as best as you can and then just realize you will need to update your code to keep it current and building with new Qt's in the future.  I've had projects that are only a few years old that have so many changes building them now would probably take me a day or 2 of time to "fix" the builds for newer Qt.  In one case I was using a webkit that Qt didn't have any more.  That one I just wrote off as a lost cause.</p>
<p dir="auto">All that is a good reason for build servers and CI.  That way you know right away when builds are broken by a dependency and can be fixed with minimal effort.  Saving it all for later will definitely bite you. :)</p>
]]></description><link>https://forum.qt.io/post/474331</link><guid isPermaLink="true">https://forum.qt.io/post/474331</guid><dc:creator><![CDATA[ambershark]]></dc:creator><pubDate>Tue, 07 Aug 2018 00:10:00 GMT</pubDate></item><item><title><![CDATA[Reply to Is it recommended to include each widget explicitly? on Mon, 06 Aug 2018 13:54:26 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/aaron-kim">@<bdi>Aaron-Kim</bdi></a> ,</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> is correct. Include only what you need. I actually take this one step farther by using forward declarations in my header and use reference and pointer in variables. This has two effects:</p>
<ol>
<li>Keep header lightweight and fast to compile because it doesn't include tons of stuff.</li>
<li>Keeps the work in the CPP file.</li>
</ol>
<p dir="auto">And, first and foremost, the usage depends on what your design intends to do.</p>
]]></description><link>https://forum.qt.io/post/474245</link><guid isPermaLink="true">https://forum.qt.io/post/474245</guid><dc:creator><![CDATA[Buckwheat]]></dc:creator><pubDate>Mon, 06 Aug 2018 13:54:26 GMT</pubDate></item><item><title><![CDATA[Reply to Is it recommended to include each widget explicitly? on Sat, 04 Aug 2018 19:48:35 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">The best practice recommends to include everything that you are using and only what you are using. Don't rely on indirect includes.</p>
<p dir="auto">In your case, you are only using QWidget based classes and it's likely also the case where this code is called, so you already include QWidget in your class header, so including it again in the implementation would be redundant.</p>
]]></description><link>https://forum.qt.io/post/473961</link><guid isPermaLink="true">https://forum.qt.io/post/473961</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 04 Aug 2018 19:48:35 GMT</pubDate></item></channel></rss>