<?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[QTableWidget segmentation fault with setTextAlignment]]></title><description><![CDATA[<p dir="auto">I really hope someone is fixing QTableWidget bugs, because this simply shouldn't happen IMHO:</p>
<pre><code>            QModelIndex index = table-&gt;model()-&gt;index(row, 0);
            table-&gt;model()-&gt;setData (index, "?", Qt::DisplayRole);
            QTableWidgetItem *item = table-&gt;item (row, 0);
            item-&gt;setTextAlignment (Qt::AlignRight);
                             ^-- crash here
</code></pre>
<p dir="auto">The table has 100 rows and 100 columns.</p>
]]></description><link>https://forum.qt.io/topic/132141/qtablewidget-segmentation-fault-with-settextalignment</link><generator>RSS for Node</generator><lastBuildDate>Mon, 19 Oct 2026 15:06:31 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/132141.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 19 Nov 2021 15:33:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QTableWidget segmentation fault with setTextAlignment on Fri, 19 Nov 2021 16:49:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a><br />
<s>[Totally out of my head, not tested.]  My understanding was that if you use the <code>setData()</code> level, that's fine, but I thought that did <em>not</em> create a <code>QTableWidgetItem</code> item for it.  <code>QTableWidget</code> does not reimplement <code>setData()</code>, so you're saying it would have to do it on <code>dataChanged()</code> signal?  (And that doesn't get emitted if you're not actually <em>changing</em> the value.)</s></p>
<p dir="auto"><strong>EDIT</strong> OK looked on <strong>woboq</strong>, agreed, it has internal <code> QTableModel::setData()</code> which does as you say about creating the item.</p>
]]></description><link>https://forum.qt.io/post/690879</link><guid isPermaLink="true">https://forum.qt.io/post/690879</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 19 Nov 2021 16:49:32 GMT</pubDate></item><item><title><![CDATA[Reply to QTableWidget segmentation fault with setTextAlignment on Fri, 19 Nov 2021 16:29:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/690871">QTableWidget segmentation fault with setTextAlignment</a>:</p>
<blockquote>
<p dir="auto">you have to put one in</p>
</blockquote>
<p dir="auto"><code>setData</code> puts the item in so it should be available afterwards</p>
]]></description><link>https://forum.qt.io/post/690876</link><guid isPermaLink="true">https://forum.qt.io/post/690876</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Fri, 19 Nov 2021 16:29:47 GMT</pubDate></item><item><title><![CDATA[Reply to QTableWidget segmentation fault with setTextAlignment on Fri, 19 Nov 2021 16:00:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/publicnamer">@<bdi>Publicnamer</bdi></a><br />
As <a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a> has asked you.</p>
<p dir="auto">I would <em>assume</em> <code>QModelIndex index = table-&gt;model()-&gt;index(row, 0);</code> returns an <em>invalid</em> index if out of range, but <code> QTableWidgetItem *item = table-&gt;item (row, 0);</code> would have to return a <code>nullptr</code>....</p>
<p dir="auto">Alternatively, you may have a valid <code>index(row, 0)</code>.  But that does not mean there is a <code>QTableWidgetItem *item</code> at <code>table-&gt;item (row, 0)</code>, cells start out with <em>no</em> <code>QTableWidgetItem</code> in them, you have to put one in, IIRC.</p>
<p dir="auto">Which would explain behaviour you see without there being any " fixing QTableWidget bugs" ?</p>
]]></description><link>https://forum.qt.io/post/690871</link><guid isPermaLink="true">https://forum.qt.io/post/690871</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 19 Nov 2021 16:00:19 GMT</pubDate></item><item><title><![CDATA[Reply to QTableWidget segmentation fault with setTextAlignment on Fri, 19 Nov 2021 15:36:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/publicnamer">@<bdi>Publicnamer</bdi></a> said in <a href="/post/690863">QTableWidget segmentation fault with setTextAlignment</a>:</p>
<blockquote>
<p dir="auto">^-- crash here</p>
</blockquote>
<p dir="auto">It should not. What version of Qt are you using? What does <code>table-&gt;model()-&gt;setData</code> return?</p>
]]></description><link>https://forum.qt.io/post/690865</link><guid isPermaLink="true">https://forum.qt.io/post/690865</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Fri, 19 Nov 2021 15:36:47 GMT</pubDate></item><item><title><![CDATA[Reply to QTableWidget segmentation fault with setTextAlignment on Fri, 19 Nov 2021 15:36:15 GMT]]></title><description><![CDATA[<p dir="auto">do you check if item is nullptr?</p>
]]></description><link>https://forum.qt.io/post/690864</link><guid isPermaLink="true">https://forum.qt.io/post/690864</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Fri, 19 Nov 2021 15:36:15 GMT</pubDate></item></channel></rss>