<?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[Why doesn&#x27;t this work?]]></title><description><![CDATA[<p dir="auto">I am debugging a project where I know some of the pointers used are <strong>nullptr</strong>, so I originally implemented calls to <strong>Q_ASSERT_X</strong> before the usage, however the execution didn't stop even though the pointer is <strong>nullptr</strong>, so I tried replacing with <strong>assert</strong>, same behaviour.</p>
<pre><code>assert(m_d!=nullptr);
return m_d-&gt;smManager;
</code></pre>
<p dir="auto">With a breakpoint on the <strong>assert</strong> I can see that <strong>m_d</strong> is <strong>nullptr</strong> but it continues on as if nothing was wrong...</p>
<p dir="auto">[Edit]<br />
Qt Creator 4.12.4<br />
Qt 5.12.2<br />
GCC 8.5.0 20210514<br />
Operating System Red Hat 8.5.0-10 64 bit</p>
]]></description><link>https://forum.qt.io/topic/140992/why-doesn-t-this-work</link><generator>RSS for Node</generator><lastBuildDate>Wed, 07 Oct 2026 18:22:59 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/140992.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 24 Nov 2022 12:23:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 16:30:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> can you copy your Q_ASSERT_X code here? As JonB wrote, use your logger code to show if it is a nullptr.<br />
Also open your Makefile in build dir and -g has to be there. If not, make distclean and rebuild your project.<br />
CFLAGS        = -pipe -g -Wall -Wextra -D_REENTRANT -fPIC $(DEFINES)<br />
CXXFLAGS      = -pipe -g -std=gnu++1z -Wall -Wextra -D_REENTRANT -fPIC $(DEFINES)</p>
<p dir="auto">if you see -g and -O2 or -O3, that is mixed build.</p>
]]></description><link>https://forum.qt.io/post/737587</link><guid isPermaLink="true">https://forum.qt.io/post/737587</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Thu, 24 Nov 2022 16:30:19 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 16:22:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a><br />
If <em>sounds</em> like you are compiling such that <code>assert</code>/<code>Q_ASSERT</code>/<code>Q_ASSERT_X</code> are no-ops.</p>
<p dir="auto">Alternatively your assumption that the pointer is null is wrong.  <em>For example</em> there are other reasons that <code>m_d-&gt;smManager</code> could crash than <code>m_d</code> being <code>nullptr</code>.</p>
<p dir="auto">There is no point guessing about compiler flags when you can just look at the compile command being executed very easily.</p>
<p dir="auto">Since you are changing code anyway, replace the <code>assert(m_d!=nullptr);</code> with something you <em>know</em> how it behaves:</p>
<pre><code>if (m_d == nullptr)
    QMessageBox() or write-to-file or whatever
</code></pre>
]]></description><link>https://forum.qt.io/post/737586</link><guid isPermaLink="true">https://forum.qt.io/post/737586</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 24 Nov 2022 16:22:37 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 16:14:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/joecfd">@<bdi>JoeCFD</bdi></a> , I commented out this line from the Makefile.  It was the only occurrence found, but still Q_ASSERT_X has no effect.</p>
]]></description><link>https://forum.qt.io/post/737583</link><guid isPermaLink="true">https://forum.qt.io/post/737583</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 24 Nov 2022 16:14:09 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 15:01:16 GMT]]></title><description><![CDATA[<p dir="auto">This line is actually not needed. But check if NDEBUG is used in your code explicitly.<br />
CONFIG(release, debug|release): DEFINES += NDEBUG</p>
<p dir="auto">if pro is used, you do not need to add anything for config. Maybe do not use mixed build "release | debug". Check the config setting in the .pro file.<br />
if cmake is used, add<br />
set( CMAKE_BUILD_TYPE Debug )</p>
<p dir="auto">Q_ASSERT() works fine in my app.</p>
]]></description><link>https://forum.qt.io/post/737571</link><guid isPermaLink="true">https://forum.qt.io/post/737571</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Thu, 24 Nov 2022 15:01:16 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 13:48:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> I know I'm building debug because I can debug, I start the process and attach using Qt Creator, I wouldn't be able to do that with source if I was running a process built for release.</p>
]]></description><link>https://forum.qt.io/post/737562</link><guid isPermaLink="true">https://forum.qt.io/post/737562</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 24 Nov 2022 13:48:38 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 13:46:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> said in <a href="/post/737556">Why doesn't this work?</a>:</p>
<blockquote>
<p dir="auto">I believe I'm building in debug mode</p>
</blockquote>
<p dir="auto">Why don't you simply check in which mode you're building?</p>
]]></description><link>https://forum.qt.io/post/737561</link><guid isPermaLink="true">https://forum.qt.io/post/737561</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 24 Nov 2022 13:46:21 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 13:45:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> I commented out that line, cleaned the project and rebuilt, the behaviour is still the same.</p>
]]></description><link>https://forum.qt.io/post/737560</link><guid isPermaLink="true">https://forum.qt.io/post/737560</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 24 Nov 2022 13:45:30 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 13:35:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> , I believe I'm building in debug mode as I can debug the C++ and the source is visible.</p>
]]></description><link>https://forum.qt.io/post/737556</link><guid isPermaLink="true">https://forum.qt.io/post/737556</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 24 Nov 2022 13:35:47 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 13:17:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> said in <a href="/post/737552">Why doesn't this work?</a>:</p>
<blockquote>
<p dir="auto">Does this explain it ?</p>
</blockquote>
<p dir="auto">The question is: do you build in debug or release mode?<br />
If in release mode then NDEBUG will be set.<br />
You can also check compiler calls to see whether NDEBUG is set or not.</p>
]]></description><link>https://forum.qt.io/post/737554</link><guid isPermaLink="true">https://forum.qt.io/post/737554</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 24 Nov 2022 13:17:41 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 13:14:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> I searched the entire project build and found this:</p>
<pre><code># Disable asserts if building in release mode
CONFIG(release, debug|release): DEFINES += NDEBUG
</code></pre>
<p dir="auto">Does this explain it ?</p>
]]></description><link>https://forum.qt.io/post/737552</link><guid isPermaLink="true">https://forum.qt.io/post/737552</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 24 Nov 2022 13:14:58 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 13:07:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> , I will investigate, I am able to debug the project, is NDEBUG required in addition to this?</p>
]]></description><link>https://forum.qt.io/post/737551</link><guid isPermaLink="true">https://forum.qt.io/post/737551</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 24 Nov 2022 13:07:48 GMT</pubDate></item><item><title><![CDATA[Reply to Why doesn&#x27;t this work? on Thu, 24 Nov 2022 13:00:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> Debug or release build?<br />
If NDEBUG is defined assert will do nothing.</p>
]]></description><link>https://forum.qt.io/post/737549</link><guid isPermaLink="true">https://forum.qt.io/post/737549</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 24 Nov 2022 13:00:39 GMT</pubDate></item></channel></rss>