<?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[Data in a single column changes --&gt;execute slot]]></title><description><![CDATA[<p dir="auto">Hi!</p>
<p dir="auto">Changing data in a QTableView, I can execute a slot like this:</p>
<pre><code>connect(ui-&gt;tblCc-&gt;model(), SIGNAL(dataChanged(const QModelIndex&amp;,const QModelIndex&amp;)), this, SLOT(onCcDataChanged()));
</code></pre>
<p dir="auto">This works fine!</p>
<p dir="auto">But how do I change the code above to execute the slot "onCcDataChange()" when values in only a single column of the QTableView are changed?</p>
<p dir="auto">Thank you!</p>
<p dir="auto">Franz</p>
]]></description><link>https://forum.qt.io/topic/63018/data-in-a-single-column-changes-execute-slot</link><generator>RSS for Node</generator><lastBuildDate>Wed, 13 May 2026 09:04:01 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/63018.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Jan 2016 08:27:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Fri, 22 Jan 2016 12:03:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mr.-kibu">@<bdi>Mr.-Kibu</bdi></a></p>
<pre><code>void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp; index)
{
    if( m_Block )
        return;

    m_Block = true;

    switch( index.column() )
    {
         case 7:
         {
                /* update column 8 */
         }
         break;
         case 8:
         {
                /* update column 7 */
         }
         break;
   }

   m_Block = false;
}
</code></pre>
]]></description><link>https://forum.qt.io/post/308894</link><guid isPermaLink="true">https://forum.qt.io/post/308894</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 22 Jan 2016 12:03:26 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Fri, 22 Jan 2016 09:16:49 GMT]]></title><description><![CDATA[<p dir="auto">Sorry, but there is no calculation on column 7 after editing column 8 :</p>
<pre><code>    if( m_Block )
        return;
    m_Block = true;

    // altering code ...
    if(index.column() == 8){
       mModCc-&gt;setData(mModCc-&gt;index(index.row(),7),ui-&gt;dsbGTotal-&gt;value()*_Percent/100,Qt::EditRole);
    }

   m_Block = false;
</code></pre>
<p dir="auto">Where do I have to write the code to calculate column 8 after editing column 7?</p>
<p dir="auto">Thank you!</p>
]]></description><link>https://forum.qt.io/post/308844</link><guid isPermaLink="true">https://forum.qt.io/post/308844</guid><dc:creator><![CDATA[Mr. Kibu]]></dc:creator><pubDate>Fri, 22 Jan 2016 09:16:49 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Fri, 22 Jan 2016 08:59:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mr.-kibu">@<bdi>Mr.-Kibu</bdi></a><br />
m_Block should of course be a member variable of your BVoucherPosForm class.<br />
And only where i wrote the comment "<strong>altering code</strong>" the actual code of the method should be placed.</p>
]]></description><link>https://forum.qt.io/post/308837</link><guid isPermaLink="true">https://forum.qt.io/post/308837</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 22 Jan 2016 08:59:57 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Fri, 22 Jan 2016 08:56:32 GMT]]></title><description><![CDATA[<p dir="auto">Where do I have to write the calculation of the columns correct? I did it this way, but it fails:</p>
<pre><code>void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp; index)
{

    if(index.column() == 8){
       mModCc-&gt;setData(mModCc-&gt;index(index.row(),7),ui-&gt;dsbGTotal-&gt;value()*_Percent/100,Qt::EditRole);
    }

    bool m_Block;
    if( m_Block )
        return;
    m_Block = true;

    // altering code ...
    if(index.column() == 7){
        mModCc-&gt;setData(mModCc-&gt;index(index.row(),8),ui-&gt;dsbGTotal-&gt;value()/_Value*100,Qt::EditRole);
    }

   m_Block = false;
}</code></pre>
]]></description><link>https://forum.qt.io/post/308835</link><guid isPermaLink="true">https://forum.qt.io/post/308835</guid><dc:creator><![CDATA[Mr. Kibu]]></dc:creator><pubDate>Fri, 22 Jan 2016 08:56:32 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Fri, 22 Jan 2016 08:05:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mr.-kibu">@<bdi>Mr.-Kibu</bdi></a><br />
add a simple recursion block:</p>
<pre><code>void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp; index)
{
    if( m_Block )
        return;
    m_Block = true;

    // altering code ...

   m_Block = false;
}
</code></pre>
]]></description><link>https://forum.qt.io/post/308831</link><guid isPermaLink="true">https://forum.qt.io/post/308831</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 22 Jan 2016 08:05:39 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Fri, 22 Jan 2016 07:08:14 GMT]]></title><description><![CDATA[<p dir="auto">Hi, I have got a first success. If I edit column 8, I can calculate a value in column 7 like this:</p>
<p dir="auto">the connect statement:</p>
<pre><code>connect(ui-&gt;tblCc-&gt;model(), &amp;QSqlRelationalTableModel::dataChanged, this, &amp;BVoucherPosForm::onCcDataChanged);
</code></pre>
<p dir="auto">and then:</p>
<pre><code>void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp; index)
{
    qDebug() &lt;&lt; Q_FUNC_INFO &lt;&lt; "COLUMN:" &lt;&lt; index.column();
    qDebug() &lt;&lt; Q_FUNC_INFO &lt;&lt; "ROW:" &lt;&lt; index.row();

    if(index.column() == 8){
       mModCc-&gt;setData(mModCc-&gt;index(index.row(),7),ui-&gt;dsbGTotal-&gt;value()*_Percent/100,Qt::EditRole);
    }
}
</code></pre>
<p dir="auto">I also get this debug-message on editing cell 1,8:</p>
<pre><code>void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp;) COLUMN: 8
void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp;) ROW: 1
void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp;) COLUMN: 7
void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp;) ROW: 1
void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp;) COLUMN: 0
void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp;) ROW: 1
</code></pre>
<p dir="auto">I don't know, why I get the debug-lines 5 and 6, and why the value in line 5 in 0 and in line 6 still 1 (??), but in works.</p>
<p dir="auto">But now there is an new problem. I would like to edit both columns, column 8 and column 7. Editing column 8 will calculate column 7 and editing column 7 will calculate column 8. On adding a if-statement to the code to control editing column 7 the way I did it above with column 8, the program crashes after editing one of the columns (the dataCanged-Signal emits endless).</p>
<p dir="auto">Is there a way to realise this, e.g. to emit the dataChanges-signal exactly on changes in a specific column?</p>
<p dir="auto">Thank you!</p>
]]></description><link>https://forum.qt.io/post/308817</link><guid isPermaLink="true">https://forum.qt.io/post/308817</guid><dc:creator><![CDATA[Mr. Kibu]]></dc:creator><pubDate>Fri, 22 Jan 2016 07:08:14 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 11:53:17 GMT]]></title><description><![CDATA[<p dir="auto">Ok, but how do I check for the index of the column I have edited?</p>
]]></description><link>https://forum.qt.io/post/308432</link><guid isPermaLink="true">https://forum.qt.io/post/308432</guid><dc:creator><![CDATA[Mr. Kibu]]></dc:creator><pubDate>Wed, 20 Jan 2016 11:53:17 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 11:02:13 GMT]]></title><description><![CDATA[<p dir="auto">the dataChanged() signal is emitted everytime some data is changed which needs to be regathered with the model's data() method.<br />
So this doesn't mean it has to be the display value only.</p>
<p dir="auto">So simply check for the column index and only do your work for the desired column and ignore the calls for the rest of the columns and you're good to go.</p>
]]></description><link>https://forum.qt.io/post/308411</link><guid isPermaLink="true">https://forum.qt.io/post/308411</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Wed, 20 Jan 2016 11:02:13 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 10:57:37 GMT]]></title><description><![CDATA[<p dir="auto">I get two messages:</p>
<p dir="auto">void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp;) COLUMN: 8<br />
void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp;) COLUMN: 0</p>
<p dir="auto">I changed an value in column 8.</p>
]]></description><link>https://forum.qt.io/post/308408</link><guid isPermaLink="true">https://forum.qt.io/post/308408</guid><dc:creator><![CDATA[Mr. Kibu]]></dc:creator><pubDate>Wed, 20 Jan 2016 10:57:37 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 10:50:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mr.-kibu">@<bdi>Mr.-Kibu</bdi></a> said:</p>
<blockquote>
<p dir="auto">Ok, a little bit better. But the "index.column()" gives me not the value of the column.</p>
</blockquote>
<p dir="auto">instead of setting the value to the spinbox try the following and check the console:</p>
<pre><code>void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp; index)
{
    qDebug() &lt;&lt; Q_FUNC_INFO &lt;&lt; "COLUMN:" &lt;&lt; index.column();
}
</code></pre>
<p dir="auto">Since you set the column on the spinbox, you will only see what was the value of the last call of your slot. That's why i added a check for the column index in my previous post, which you completely left out in your last snippet.</p>
]]></description><link>https://forum.qt.io/post/308401</link><guid isPermaLink="true">https://forum.qt.io/post/308401</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Wed, 20 Jan 2016 10:50:44 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 09:45:05 GMT]]></title><description><![CDATA[<p dir="auto">Ok, a little bit better. But the "index.column()" gives me not the value of the column.<br />
I have:</p>
<pre><code>connect(ui-&gt;tblCc-&gt;model(), &amp;QSqlRelationalTableModel::dataChanged, this, &amp;BVoucherPosForm::onCcDataChanged);
</code></pre>
<p dir="auto">and</p>
<pre><code>void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp; index)
{
    ui-&gt;change-&gt;setText("ccc");
    ui-&gt;spinBox-&gt;setValue(index.column());
}
The QLAbel is "ccc" but the Spinbox is "0".

Thank you!</code></pre>
]]></description><link>https://forum.qt.io/post/308377</link><guid isPermaLink="true">https://forum.qt.io/post/308377</guid><dc:creator><![CDATA[Mr. Kibu]]></dc:creator><pubDate>Wed, 20 Jan 2016 09:45:05 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 09:33:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a> said:</p>
<blockquote>
<p dir="auto">just to add: you also need a C++11 supported compiler.</p>
</blockquote>
<p dir="auto">Well spotted.</p>
]]></description><link>https://forum.qt.io/post/308373</link><guid isPermaLink="true">https://forum.qt.io/post/308373</guid><dc:creator><![CDATA[ValentinMichelet]]></dc:creator><pubDate>Wed, 20 Jan 2016 09:33:48 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 09:27:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/valentinmichelet">@<bdi>ValentinMichelet</bdi></a> said:</p>
<blockquote>
<p dir="auto">If you use Qt5, you can use the new syntax:</p>
</blockquote>
<p dir="auto">just to add: you also need a C++11 supported compiler.</p>
]]></description><link>https://forum.qt.io/post/308371</link><guid isPermaLink="true">https://forum.qt.io/post/308371</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Wed, 20 Jan 2016 09:27:20 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 09:20:58 GMT]]></title><description><![CDATA[<p dir="auto">If you use Qt5, you can use the new syntax:</p>
<pre><code>connect(sender, &amp;Sender::valueChanged, receiver, &amp;Receiver::updateValue);
</code></pre>
<p dir="auto">Which here would be:</p>
<pre><code>connect(ui-&gt;tblCc-&gt;model(), &amp;QSqlRelationalTableModel::dataChanged, this, &amp;BVoucherPosForm::onCcDataChanged);
</code></pre>
<p dir="auto">This syntax has the advantage to be evaluated at compile time, giving you an explicit error, rather than a silently output at run time.</p>
]]></description><link>https://forum.qt.io/post/308368</link><guid isPermaLink="true">https://forum.qt.io/post/308368</guid><dc:creator><![CDATA[ValentinMichelet]]></dc:creator><pubDate>Wed, 20 Jan 2016 09:20:58 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 09:19:20 GMT]]></title><description><![CDATA[<p dir="auto">Nothing changes. I do:</p>
<pre><code>connect(ui-&gt;tblCc-&gt;model(), SIGNAL(dataChanged(const QModelIndex&amp;,const QModelIndex&amp;)), this, SLOT(onCcDataChanged()));
</code></pre>
<p dir="auto">and get the error:<br />
"QObject::connect: No such slot BVoucherPosForm::onCcDataChanged()"</p>
]]></description><link>https://forum.qt.io/post/308367</link><guid isPermaLink="true">https://forum.qt.io/post/308367</guid><dc:creator><![CDATA[Mr. Kibu]]></dc:creator><pubDate>Wed, 20 Jan 2016 09:19:20 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 09:07:05 GMT]]></title><description><![CDATA[<p dir="auto">remove the parameter name from the slot in the connect-statement.</p>
]]></description><link>https://forum.qt.io/post/308364</link><guid isPermaLink="true">https://forum.qt.io/post/308364</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Wed, 20 Jan 2016 09:07:05 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 09:03:04 GMT]]></title><description><![CDATA[<p dir="auto">Thank you for your quick answer! I changed the code like this:</p>
<pre><code>    connect(ui-&gt;tblCc-&gt;model(), SIGNAL(dataChanged(const QModelIndex&amp;,const QModelIndex&amp;)), this, SLOT(onCcDataChanged(const QModelIndex&amp; index)));
</code></pre>
<p dir="auto">and</p>
<pre><code>void BVoucherPosForm::onCcDataChanged(const QModelIndex&amp; index)
{
    ui-&gt;change-&gt;setText("ccc");


    if(index.column() == 8){
        ui-&gt;change-&gt;setText("xxx");
    }
}
</code></pre>
<p dir="auto">But I don't get either "ccc" or a "xxx" in my QLabel (change).</p>
<p dir="auto">I also get the error "QObject::connect: No such signal QSqlRelationalTableModel::dataChanged(const QModelIndex&amp; index)".</p>
<p dir="auto">What I am doing wrong?</p>
]]></description><link>https://forum.qt.io/post/308363</link><guid isPermaLink="true">https://forum.qt.io/post/308363</guid><dc:creator><![CDATA[Mr. Kibu]]></dc:creator><pubDate>Wed, 20 Jan 2016 09:03:04 GMT</pubDate></item><item><title><![CDATA[Reply to Data in a single column changes --&gt;execute slot on Wed, 20 Jan 2016 08:33:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mr.-kibu">@<bdi>Mr.-Kibu</bdi></a><br />
the dataChanged() signal already comes with the QModelIndex which has changed.<br />
Simply check this model index in your slot.</p>
<pre><code>connect(ui-&gt;tblCc-&gt;model(), SIGNAL(dataChanged(const QModelIndex&amp;,const QModelIndex&amp;)), this, SLOT(onCcDataChanged(const QModelIndex&amp;));
...
void onCcDataChanged(const QModelIndex&amp; index)
{
     if( index.column() != DESIRED_COLUMN )
         return;
    //...
}
</code></pre>
]]></description><link>https://forum.qt.io/post/308354</link><guid isPermaLink="true">https://forum.qt.io/post/308354</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Wed, 20 Jan 2016 08:33:52 GMT</pubDate></item></channel></rss>