<?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 data to xml file]]></title><description><![CDATA[<p dir="auto">for(iRow = 0; iRow &lt; 10; iRow ++)<br />
{<br />
QDomElement deName = xmlfeature.createElement("Name");<br />
deStudent.appendChild(deName);<br />
int iData = ui-&gt;tableWidget_data-&gt;item(iRow,0)-&gt;text().toInt();<br />
QDomText dtData = xmlFeature.createTextNode(QString::number(iData));<br />
deName.appendChild(dtData);<br />
}</p>
<p dir="auto">I am using this code to access the rows in a TableWidget</p>
<p dir="auto">However the program crashes and the values from the table are not written into the XML file.</p>
<p dir="auto">Where am I going wrong?</p>
<p dir="auto">Also I want to see if the value in the row iRow,0 in a table is empty or not. It should not have garbage value either</p>
<p dir="auto">How do I check this?<br />
The total number of tags that I want to create in my xml file should be equal to the number of non empty rows in the table.</p>
<p dir="auto">How do I do that?<br />
Please help</p>
]]></description><link>https://forum.qt.io/topic/138606/qtablewidget-data-to-xml-file</link><generator>RSS for Node</generator><lastBuildDate>Sat, 02 May 2026 01:36:45 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/138606.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Aug 2022 11:47:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QTableWidget data to xml file on Mon, 15 Aug 2022 18:26:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qtishard">@<bdi>QtisHard</bdi></a> said in <a href="/post/724908">QTableWidget data to xml file</a>:</p>
<blockquote>
<p dir="auto">10 is the number of rows that I have defined my table to have. The total number of rows cannot cross 10.  So I am iterating the entire table and then seeing if there is any value in that row in the table.</p>
</blockquote>
<p dir="auto">It does not change the fact that you are using a magic number for that. The loop should always run on the actual row count of the model. What when you decide that it's not 10 but 12 rows ? Defining the size in the rowCount method allows to have the information in one central place.</p>
<blockquote>
<p dir="auto">I am converting the value in the cell to an integer value and storing it in iData<br />
Then to store that value into the XML file I convert it to a string so that it can be stored a value in a tag.</p>
</blockquote>
<p dir="auto">Then again: why the double conversion ? Just get the value as text directly.</p>
<blockquote>
<p dir="auto">A non empty row would be on that has no value in it at all.<br />
So it should not have any value in it.</p>
</blockquote>
<p dir="auto">The way you describe it makes it look that the row might now have any items in it and you are not checking for that.</p>
]]></description><link>https://forum.qt.io/post/724930</link><guid isPermaLink="true">https://forum.qt.io/post/724930</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 15 Aug 2022 18:26:51 GMT</pubDate></item><item><title><![CDATA[Reply to QTableWidget data to xml file on Mon, 15 Aug 2022 14:06:15 GMT]]></title><description><![CDATA[<p dir="auto">where is the crash location? Is  ui-&gt;tableWidget_data-&gt;item(iRow,0) nullptr or not?</p>
]]></description><link>https://forum.qt.io/post/724910</link><guid isPermaLink="true">https://forum.qt.io/post/724910</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Mon, 15 Aug 2022 14:06:15 GMT</pubDate></item><item><title><![CDATA[Reply to QTableWidget data to xml file on Mon, 15 Aug 2022 13:47:56 GMT]]></title><description><![CDATA[<p dir="auto">10 is the number of rows that I have defined my table to have. The total number of rows cannot cross 10.  So I am iterating the entire table and then seeing if there is any value in that row in the table.</p>
<p dir="auto">I am converting the value in the cell to an integer value and storing it in iData<br />
Then to store that value into the XML file I convert it to a string so that it can be stored a value in a tag.</p>
<p dir="auto">A non empty row would be on that has no value in it at all.<br />
So it should not have any value in it.</p>
]]></description><link>https://forum.qt.io/post/724908</link><guid isPermaLink="true">https://forum.qt.io/post/724908</guid><dc:creator><![CDATA[QtisHard]]></dc:creator><pubDate>Mon, 15 Aug 2022 13:47:56 GMT</pubDate></item><item><title><![CDATA[Reply to QTableWidget data to xml file on Mon, 15 Aug 2022 12:02:50 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">There are several issues in your code:</p>
<ol>
<li>Use of magic numbers. Where is that 10 coming from ? You do not take into account the real numbers of row from your QTableWidget so you might be accessing invalid items through invalid indexes.</li>
<li>Why are you converting a textual value to and int to immediately converting back to a string ?</li>
</ol>
<p dir="auto">As for your checks, loop over the actual count of rows, if it's zero then nothing will happen. As for non empty rows, how do you define a row to be empty ? Once you know that, us it as a condition to not process the row in question.</p>
]]></description><link>https://forum.qt.io/post/724892</link><guid isPermaLink="true">https://forum.qt.io/post/724892</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 15 Aug 2022 12:02:50 GMT</pubDate></item></channel></rss>