<?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[Overriding closeEvent without child class]]></title><description><![CDATA[<p dir="auto">I saw an application with following override</p>
<pre><code>void QDockWidget::closeEvent(QCloseEvent* e)
{
  //handling close event here
}
</code></pre>
<p dir="auto">How it is not a redefinition? Qt must be defining the QDockWidget::closeEvent() function by itself. How can we redefine that function? I know C++ override, but I thought it is possible only by creating a child class. But there is <strong>no child class</strong> in this this case. By the way the above code is working perfectly fine !! How?</p>
]]></description><link>https://forum.qt.io/topic/73410/overriding-closeevent-without-child-class</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 03:14:49 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/73410.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 Nov 2016 14:52:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Overriding closeEvent without child class on Thu, 17 Nov 2016 06:13:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qmad">@<bdi>qmad</bdi></a> Now that I get what you're asking that is indeed weird.  The one thing I can think of as well is that it is not defined in Qt itself, so there is no naming conflict when redefining it.</p>
<p dir="auto">Seems like a dangerous game that author was playing regardless though.  I'd like to write some test code and play with that a bit more.  It doesn't seem valid. :)</p>
]]></description><link>https://forum.qt.io/post/360043</link><guid isPermaLink="true">https://forum.qt.io/post/360043</guid><dc:creator><![CDATA[ambershark]]></dc:creator><pubDate>Thu, 17 Nov 2016 06:13:23 GMT</pubDate></item><item><title><![CDATA[Reply to Overriding closeEvent without child class on Thu, 17 Nov 2016 06:12:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ambershark">@<bdi>ambershark</bdi></a><br />
Yes<br />
In my opinion, the only way it can work is Qt left the closeEvent() function undefined inside QDocWidget class.<br />
Or is there any C++ or Qt magic I am not aware of?</p>
]]></description><link>https://forum.qt.io/post/360042</link><guid isPermaLink="true">https://forum.qt.io/post/360042</guid><dc:creator><![CDATA[qmad]]></dc:creator><pubDate>Thu, 17 Nov 2016 06:12:47 GMT</pubDate></item><item><title><![CDATA[Reply to Overriding closeEvent without child class on Thu, 17 Nov 2016 06:10:24 GMT]]></title><description><![CDATA[<p dir="auto">OH! I think I see what you are talking about.  The QDockWidget::closeEvent override was in some random cpp file.  Not in the Qt files.  I thought you were confused on inheritance and virtual functions, but really you're saying someone just randomly redefined a virtual from a class it wasn't part of?</p>
]]></description><link>https://forum.qt.io/post/360040</link><guid isPermaLink="true">https://forum.qt.io/post/360040</guid><dc:creator><![CDATA[ambershark]]></dc:creator><pubDate>Thu, 17 Nov 2016 06:10:24 GMT</pubDate></item><item><title><![CDATA[Reply to Overriding closeEvent without child class on Thu, 17 Nov 2016 06:09:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a></p>
<p dir="auto">Let us say class A is defined in a library as follows</p>
<pre><code>class A
{
  public:
   virtual int fun();
};

int A::fun()
{
   cout&lt;&lt;"Called from library";
}
</code></pre>
<p dir="auto">And in my main.cpp can I have below code?</p>
<pre><code>main()
{
  A a;
  a.fun();
}

int A::fun()
{
  cout&lt;&lt;"called from Main";
}
</code></pre>
]]></description><link>https://forum.qt.io/post/360038</link><guid isPermaLink="true">https://forum.qt.io/post/360038</guid><dc:creator><![CDATA[qmad]]></dc:creator><pubDate>Thu, 17 Nov 2016 06:09:46 GMT</pubDate></item><item><title><![CDATA[Reply to Overriding closeEvent without child class on Thu, 17 Nov 2016 06:04:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qmad">@<bdi>qmad</bdi></a> I don't think you get it.  The QDockWidget IS the child class where it is overridden.  You can of course derive from QDockWidget and override it again yourself.</p>
]]></description><link>https://forum.qt.io/post/360037</link><guid isPermaLink="true">https://forum.qt.io/post/360037</guid><dc:creator><![CDATA[ambershark]]></dc:creator><pubDate>Thu, 17 Nov 2016 06:04:30 GMT</pubDate></item><item><title><![CDATA[Reply to Overriding closeEvent without child class on Thu, 17 Nov 2016 05:27:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qmad">@<bdi>qmad</bdi></a> Where is this code from?</p>
<pre><code>void QDockWidget::closeEvent(QCloseEvent* e)
{
  //handling close event here
}
</code></pre>
<p dir="auto">It is just a plain old C++ method definition, which in this case happens to be an inherited virtual method, hence it is overridden in QDockWidget.</p>
]]></description><link>https://forum.qt.io/post/360030</link><guid isPermaLink="true">https://forum.qt.io/post/360030</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 17 Nov 2016 05:27:30 GMT</pubDate></item><item><title><![CDATA[Reply to Overriding closeEvent without child class on Thu, 17 Nov 2016 04:46:49 GMT]]></title><description><![CDATA[<p dir="auto">I can understand if there is a child class of QDocWidget and closeEvent is overriding in it. In this case simply there is a QDockWidget::closeEvent(QCloseEvent* e){----} code. I was assuming that this definition will be already there in Qt libraries. Do you mean, in QtDocWidget, it is only a declaration and they left definition of us ?</p>
]]></description><link>https://forum.qt.io/post/360026</link><guid isPermaLink="true">https://forum.qt.io/post/360026</guid><dc:creator><![CDATA[qmad]]></dc:creator><pubDate>Thu, 17 Nov 2016 04:46:49 GMT</pubDate></item><item><title><![CDATA[Reply to Overriding closeEvent without child class on Wed, 16 Nov 2016 22:24:32 GMT]]></title><description><![CDATA[<p dir="auto">QDockWidget's parent is QWidget.  So it is a child to QWidget.  And <code>QWidget::closeEvent()</code> is a protected virtual so it can be overridden.</p>
<p dir="auto">Likewise if you wanted to override <code>closeEvent</code> in a class you derive from <code>QDockWidget</code>  you would be able to do that as well.</p>
<p dir="auto">So the override is legit since QDockWidget is a child of QWidget. ;)</p>
<p dir="auto">Edit: I really should have read <a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a> 's answer before I wrote that since he said exactly what I said.</p>
]]></description><link>https://forum.qt.io/post/359999</link><guid isPermaLink="true">https://forum.qt.io/post/359999</guid><dc:creator><![CDATA[ambershark]]></dc:creator><pubDate>Wed, 16 Nov 2016 22:24:32 GMT</pubDate></item><item><title><![CDATA[Reply to Overriding closeEvent without child class on Wed, 16 Nov 2016 14:55:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qmad">@<bdi>qmad</bdi></a> said in <a href="/post/359943">Overriding closeEvent without child class</a>:</p>
<blockquote>
<p dir="auto">But there is no child class in this this case.</p>
</blockquote>
<p dir="auto">i am not quite sure what your question is, but i try it anyway.<br />
The QWidget base class implements closeEvent(). Additionally it's declared as <code>virtual</code></p>
]]></description><link>https://forum.qt.io/post/359944</link><guid isPermaLink="true">https://forum.qt.io/post/359944</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Wed, 16 Nov 2016 14:55:13 GMT</pubDate></item></channel></rss>