<?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[Get index Row in QTableWidget [SOLVED]]]></title><description><![CDATA[<p dir="auto">Hi Qt Warrior...<br />
i have got some of  problem to get index row on the QTableWidget</p>
<p dir="auto">this is the link of  snapshot i have been created:<br />
<a href="http://pbrd.co/1foTebD" target="_blank" rel="noopener noreferrer nofollow ugc">http://pbrd.co/1foTebD</a></p>
<p dir="auto">snappet code:<br />
@<br />
MainWindow::MainWindow(QWidget *parent)<br />
: QMainWindow(parent),ui(new Ui::MainWindow)<br />
{<br />
ui-&gt;setUpUi(this);</p>
<p dir="auto">QSqlQuery query ("select *from employees");;<br />
ui-&gt;tableWidget-&gt;setRowCount(query.size());<br />
ui-&gt;tableWidget-&gt;setHorizontalHeaderLabels(QString(" IDdbEmp ; Last Name  ; First Name ; Email ; Country").split(";"));</p>
<p dir="auto">signalMapper = new QSignalMapper(this);<br />
int size = ui-&gt;tableWidget-&gt;rowCount();<br />
for ( y=0; y &lt; size ; ++y)<br />
{<br />
query.next();<br />
detailButton = new QPushButton(this);<br />
detailButton-&gt;setText(QString::fromUtf8("Delete"));<br />
ui-&gt;tableWidget-&gt;setItem(y,0,new QTableWidgetItem(query.value(0).toString()));<br />
ui-&gt;tableWidget-&gt;setItem(y,1,new QTableWidgetItem(query.value(1).toString()));<br />
ui-&gt;tableWidget-&gt;setItem(y,2,new QTableWidgetItem(query.value(2).toString()));<br />
ui-&gt;tableWidget-&gt;setItem(y,3,new QTableWidgetItem(query.value(3).toString()));<br />
ui-&gt;tableWidget-&gt;setItem(y,4,new QTableWidgetItem(query.value(4).toString()));<br />
ui-&gt;tableWidget-&gt;setCellWidget(y,5,detailButton);<br />
connect(detailButton,SIGNAL(clicked()),signalMapper,SLOT(map()));<br />
signalMapper-&gt;setMapping(detailButton,y);<br />
}</p>
<p dir="auto">query.clear();</p>
<p dir="auto">connect(signalMapper,SIGNAL(mapped(int)),this,SLOT(detail(int)));<br />
connect(ui-&gt;button1,SIGNAL(clicked()),this,SLOT(plus()));</p>
<p dir="auto">}</p>
<p dir="auto">MainWindow::~MainWindow()<br />
{<br />
delete ui;</p>
<p dir="auto">}</p>
<p dir="auto">void MainWindow::plus()<br />
{</p>
<pre><code>  /*! if(!(emp))
    emp= new EmployeeOrg(this);
    emp-&gt;show();*/
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void MainWindow::detail(int row)<br />
{</p>
<p dir="auto">//ui-&gt;statusBar-&gt;showMessage(QString::fromUtf8("PushButton changet at row %1, value at: %2 ").arg(row+1));<br />
qDebug()&lt;&lt; ui-&gt;tableWidget-&gt;item(row, 0)-&gt;text();</p>
<pre><code>ui-&gt;tableWidget-&gt;removeRow(row );
QSqlQuery query;
query.exec&amp;#40;QString("delete from employees where empID=%1"&amp;#41;.arg(row&amp;#41;&amp;#41;;
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto">when i click the button of Delete , the query of delete not working well</p>
<p dir="auto">I hope the Qt warrior can give the best solution for my problem<br />
Thanks :)</p>
]]></description><link>https://forum.qt.io/topic/37858/get-index-row-in-qtablewidget-solved</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 17:36:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/37858.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 15 Feb 2014 15:50:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Get index Row in QTableWidget [SOLVED] on Sat, 15 Feb 2014 18:55:15 GMT]]></title><description><![CDATA[<p dir="auto">thanks dude<br />
its work</p>
<p dir="auto">when i deleted of each row in qtablewidget, also i need to know the empID on my database<br />
:)</p>
]]></description><link>https://forum.qt.io/post/214997</link><guid isPermaLink="true">https://forum.qt.io/post/214997</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sat, 15 Feb 2014 18:55:15 GMT</pubDate></item><item><title><![CDATA[Reply to Get index Row in QTableWidget [SOLVED] on Sat, 15 Feb 2014 18:08:17 GMT]]></title><description><![CDATA[<p dir="auto">How is it that row numer corresppnds to emplD in database.  Should it not be:<br />
str =  "delete from employees where empID=" + item(row, 0)-&gt;text();<br />
query.exec(str);</p>
<p dir="auto">Also  you should check the status of your exec. Something like:</p>
<p dir="auto">bstatus = query.exec();<br />
if (bstatus == false) {<br />
sqlError = query.lastError();<br />
errorMessage = sqlError.databaseText();<br />
qWarning() &lt;&lt; errorMessage;<br />
}</p>
]]></description><link>https://forum.qt.io/post/214996</link><guid isPermaLink="true">https://forum.qt.io/post/214996</guid><dc:creator><![CDATA[DBoosalis]]></dc:creator><pubDate>Sat, 15 Feb 2014 18:08:17 GMT</pubDate></item></channel></rss>