<?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[Item delegation? how does it work?]]></title><description><![CDATA[<p dir="auto">I'm working on a form which shows and updates a database table T_SRM_cars. This table has a foreign key to a table T_SRM_drivers.<br />
This form shows the info of one record at a time and has buttons to go to the next or previous record and to add a new record.</p>
<p dir="auto">In my form I have a combobox cb_owner which must contain the pseudonym names of all the car owners, which are in the driver table. The combobox shows the name of the driver who owns the specific car. it should be possible to change the owner of the car by selecting a different name in the combobox.</p>
<p dir="auto">The program so far works allmost: If the driver_id field in a record in the cars table contains a correct id, the combobox does show the correct owmer, and the combobox does contain the all the pseudonym names from the driver table, but what do i need to do in order to update the driver_id field in the cars table to the driver selected in the combobox.</p>
<p dir="auto">Do I need Item delegation? And how should I use it?</p>
<p dir="auto">I've seen the books example, but I don't want to use the QTableView.<br />
I've also seen the SQLWidgetmapper example, but that one does not work correctly. It does not update the addresstype_id in my database.</p>
<p dir="auto">I've also thought of using a slot on the combobox. I think the slot on_cb_owner_activated(int index), but I don't know what I should update, when the user selects another driver from the combobox.</p>
<p dir="auto">void Form_cars::on_cb_owner_activated(int index)<br />
{<br />
//What should I do over here?<br />
}</p>
<p dir="auto">This is the code from the constructor:</p>
<p dir="auto">Form_cars::Form_cars(QWidget *parent) :<br />
QWidget(parent),<br />
ui(new Ui::Form_cars)<br />
{<br />
ui-&gt;setupUi(this);</p>
<pre><code>model = new QSqlRelationalTableModel(this);
model-&gt;setTable("T_SRM_cars");
model-&gt;setEditStrategy(QSqlTableModel::OnManualSubmit);

// Remember the indexes of the columns
driver_id = model-&gt;fieldIndex("driver_id");

// Set the relations to the other database tables
model-&gt;setRelation(driver_id, QSqlRelation("T_SRM_drivers", "id", "pseudonym"));

model-&gt;select();

ui-&gt;cb_owner-&gt;setModel(model-&gt;relationModel(driver_id));
ui-&gt;cb_owner-&gt;setModelColumn(model-&gt;relationModel(driver_id)-&gt;fieldIndex("pseudonym"));

mapper = new QDataWidgetMapper(this);
mapper-&gt;setModel(model);

mapper-&gt;addMapping(ui-&gt;le_name, model-&gt;fieldIndex("name"));
mapper-&gt;addMapping(ui-&gt;cb_owner, driver_id);
mapper-&gt;addMapping(ui-&gt;le_brand, model-&gt;fieldIndex("brand"));
mapper-&gt;addMapping(ui-&gt;le_model, model-&gt;fieldIndex("model"));

if (model-&gt;rowCount()==0) {
    model-&gt;database().transaction();
    if (model-&gt;insertRow(model-&gt;rowCount())) {
        mapper-&gt;toLast();
    } else {
        QMessageBox::warning(this, tr("T_SRM_drivers"),
                             tr("The database reported an error: %1")
                             .arg(model-&gt;lastError().text()));
    }
}

mapper-&gt;toFirst();
</code></pre>
<p dir="auto">}</p>
<p dir="auto">Regards,</p>
<p dir="auto">Gerrit Zijlstra</p>
]]></description><link>https://forum.qt.io/topic/66337/item-delegation-how-does-it-work</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 03:47:23 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/66337.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 22 Apr 2016 18:42:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Item delegation? how does it work? on Sat, 30 Apr 2016 00:04:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gerrit-zijlstra">@<bdi>Gerrit-Zijlstra</bdi></a><br />
Seeing that <a href="https://bugreports.qt.io/browse/QTBUG-50780?jql=issuetype%20%3D%20Bug%20AND%20text%20~%20QDataWidgetMapper" target="_blank" rel="noopener noreferrer nofollow ugc">Joe's bug report</a> is still hanging out there I don't know what to suggest. As I see it, you have two options: either you give up on that widget and use a custom/manually populated widget, or you try tracing the problem in the debugger, fix it up yourself and upload the patch. Sorry, I know of no workarounds for this. I remember only superficially inspecting the <code>QDataWidgetMapper</code> then, as I had no time to really dig in deeper.</p>
]]></description><link>https://forum.qt.io/post/324925</link><guid isPermaLink="true">https://forum.qt.io/post/324925</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Sat, 30 Apr 2016 00:04:20 GMT</pubDate></item><item><title><![CDATA[Reply to Item delegation? how does it work? on Fri, 29 Apr 2016 23:05:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kshegunov">@<bdi>kshegunov</bdi></a> Thanks. It looks like the same isue, but the problem is, that it is not solved and I don't know how to get around it. . .<br />
I allready made a bug report, with a simple sample program.<br />
Do you have an idea of how to get around this problem? I really would like to use the combobox for referencing other tables using the id.</p>
]]></description><link>https://forum.qt.io/post/324921</link><guid isPermaLink="true">https://forum.qt.io/post/324921</guid><dc:creator><![CDATA[Gerrit Zijlstra]]></dc:creator><pubDate>Fri, 29 Apr 2016 23:05:41 GMT</pubDate></item><item><title><![CDATA[Reply to Item delegation? how does it work? on Fri, 29 Apr 2016 18:25:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gerrit-zijlstra">@<bdi>Gerrit-Zijlstra</bdi></a><br />
I recall <a href="http://forum.qt.io/topic/63442/sql-widget-mapper-example-weirdness" target="_blank" rel="noopener noreferrer nofollow ugc">tracing such issue</a> some time ago, but I was not able to find the exact problem. Still, judging from the thread it seems I believed there's a bug in the widget mapper's handling of combo boxes. Sadly the original poster didn't share the bug report link.</p>
]]></description><link>https://forum.qt.io/post/324873</link><guid isPermaLink="true">https://forum.qt.io/post/324873</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Fri, 29 Apr 2016 18:25:19 GMT</pubDate></item><item><title><![CDATA[Reply to Item delegation? how does it work? on Fri, 29 Apr 2016 14:21:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Do you know if there is a workaround on my problem?<br />
Is there a way to set the value in the model or mapping after the user has selected a row in the combobox, so that the correct value is inserted in the database?</p>
<p dir="auto">I have created a new bug report about 4 days ago.<br />
<a href="https://bugreports.qt.io/browse/QTBUG-52986" target="_blank" rel="noopener noreferrer nofollow ugc">https://bugreports.qt.io/browse/QTBUG-52986</a></p>
<p dir="auto">It is asigned to someone, but there is no activity on it.<br />
The person to which it has been assigned, hasn't been active for two weeks. . .</p>
<p dir="auto">Regards,</p>
<p dir="auto">Gerrit</p>
]]></description><link>https://forum.qt.io/post/324855</link><guid isPermaLink="true">https://forum.qt.io/post/324855</guid><dc:creator><![CDATA[Gerrit Zijlstra]]></dc:creator><pubDate>Fri, 29 Apr 2016 14:21:26 GMT</pubDate></item><item><title><![CDATA[Reply to Item delegation? how does it work? on Sun, 24 Apr 2016 19:53:36 GMT]]></title><description><![CDATA[<p dir="auto">I haven't seen anything obviously wrong with your example so. You should login on the bug report system, and IIRC, you should have a plus sign on the right of the Attachments line</p>
]]></description><link>https://forum.qt.io/post/323937</link><guid isPermaLink="true">https://forum.qt.io/post/323937</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sun, 24 Apr 2016 19:53:36 GMT</pubDate></item><item><title><![CDATA[Reply to Item delegation? how does it work? on Sat, 23 Apr 2016 18:29:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Hi,</p>
<p dir="auto">I don't know if it's related, but I have created an example program. I don't know how to add it to the bug report, but I will post the  files in my dropbox. Maybe you can check if it is related to the QTBUG.</p>
<p dir="auto">I work with a sqlite database test.db which is opened in initdb.h. Please change the database to select your own.</p>
<p dir="auto">The program creates two tables: drivers and cars. The table cars reference the drivers table. Some records are inserted in each table.</p>
<p dir="auto">The form shows the cars table and the combobox shows the lastname of the driver.<br />
The driver_id in the cars table does not get updated which should be the bug. . .</p>
<p dir="auto">In mainwindow.cpp and mainwindow .h I commented out the code for a simple non relational table version. If I comment the relationaltable version out instead of the table version, the program does update the drivers_id field.</p>
<p dir="auto">You can download the files from :<br />
<a href="https://www.dropbox.com/sh/4qepkporuk1tndm/AAD1gOhUorK1pTbjl0H2bR2Ha?dl=0" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.dropbox.com/sh/4qepkporuk1tndm/AAD1gOhUorK1pTbjl0H2bR2Ha?dl=0</a></p>
<p dir="auto">Regards and thanks for helping again,</p>
<p dir="auto">Gerrit Zijlstra<br />
Hopefull my little example can help fixing a bug, or maybe I'm just forgetting something.</p>
]]></description><link>https://forum.qt.io/post/323826</link><guid isPermaLink="true">https://forum.qt.io/post/323826</guid><dc:creator><![CDATA[Gerrit Zijlstra]]></dc:creator><pubDate>Sat, 23 Apr 2016 18:29:27 GMT</pubDate></item><item><title><![CDATA[Reply to Item delegation? how does it work? on Fri, 22 Apr 2016 20:34:21 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I wonder if it's related to <a href="https://bugreports.qt.io/browse/QTBUG-16299?jql=text%20~%20%22qdatawidgetmapper%22" target="_blank" rel="noopener noreferrer nofollow ugc">QTBUG-16299</a>.</p>
<p dir="auto">Can you create a minimal compilable example that shows that behavior ? If so, please add it to the bug report.</p>
]]></description><link>https://forum.qt.io/post/323757</link><guid isPermaLink="true">https://forum.qt.io/post/323757</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 22 Apr 2016 20:34:21 GMT</pubDate></item><item><title><![CDATA[Reply to Item delegation? how does it work? on Fri, 22 Apr 2016 19:58:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> This is how the table is created in sqlite:</p>
<p dir="auto">CREATE TABLE IF NOT EXISTS T_SRM_cars  (id integer primary key,<br />
name varchar(30),<br />
driver_id integer REFERENCES T_SRM_drivers (id),<br />
brand varchar(20),<br />
model varchar(30),<br />
cartype_id integer REFERENCES T_SRM_cartype (id) );</p>
<p dir="auto">and yes, the driver_id references the id field from the T_SRM_drivers but it does not have a foreign key constraint yet.<br />
(The field for cartype_id is not used yet, but will be used the same way as the driver_id. )</p>
]]></description><link>https://forum.qt.io/post/323748</link><guid isPermaLink="true">https://forum.qt.io/post/323748</guid><dc:creator><![CDATA[Gerrit Zijlstra]]></dc:creator><pubDate>Fri, 22 Apr 2016 19:58:39 GMT</pubDate></item><item><title><![CDATA[Reply to Item delegation? how does it work? on Fri, 22 Apr 2016 19:48:55 GMT]]></title><description><![CDATA[<p dir="auto">Ok,<br />
Hmm<br />
Is there anything special with driver_id in the database  ?<br />
Key, constrains etc ?</p>
<p dir="auto">As far as I know, it should just work as the other fields.</p>
<p dir="auto">Well, delegates are used with views. Its part of the model/view concept so its<br />
not possible to apply to a normal widget, but it would not really make sense anyway since<br />
its for altering a views way of handling the data from the model.</p>
]]></description><link>https://forum.qt.io/post/323746</link><guid isPermaLink="true">https://forum.qt.io/post/323746</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 22 Apr 2016 19:48:55 GMT</pubDate></item><item><title><![CDATA[Reply to Item delegation? how does it work? on Fri, 22 Apr 2016 19:23:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> The code for submitting is allready included somewhere else, It is done, everytime one of the other fields in the form is changed by the user.  I´ve also tried to put that same code in the slot I mentioned, but I´m missing the connection from the combobox back to the field in the database table. Updating all the other collumns in the databas works correctly. Only the driver_id field does not change, and is left empty when I create a new record.</p>
<p dir="auto">If Delegate is not common in this context, then I need to know how to change the contents of the driver_id in my mapping somehow to the id of the selected driver in the combobox.</p>
]]></description><link>https://forum.qt.io/post/323745</link><guid isPermaLink="true">https://forum.qt.io/post/323745</guid><dc:creator><![CDATA[Gerrit Zijlstra]]></dc:creator><pubDate>Fri, 22 Apr 2016 19:23:03 GMT</pubDate></item><item><title><![CDATA[Reply to Item delegation? how does it work? on Fri, 22 Apr 2016 18:58:09 GMT]]></title><description><![CDATA[<p dir="auto">hi<br />
you are using  OnManualSubmit so i think you need to call<br />
<a href="http://doc.qt.io/qt-5/qsqltablemodel.html#submitAll" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qsqltablemodel.html#submitAll</a><br />
for it to save. (in the cb slot)</p>
<p dir="auto">Item delegation ?<br />
Do you mean a Delegate ?<br />
<a href="http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html</a><br />
Delegates are used with views to alter default editing or showing in the/a view.<br />
Since u are using QDataWidgetMapper and normal widgets, delegates are not<br />
so common in this context.</p>
]]></description><link>https://forum.qt.io/post/323740</link><guid isPermaLink="true">https://forum.qt.io/post/323740</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 22 Apr 2016 18:58:09 GMT</pubDate></item></channel></rss>