<?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[Calling the data method of a QAbstractItemModel in QML always uses display role instead of the requested role]]></title><description><![CDATA[<p dir="auto">I'm implementing an editor for my QAbstractItemModel subclass, so I started by getting it's edit role data into an edit dialog:</p>
<pre><code class="language-qml">TextField {
    text: nbtTree.data(editPopup.index, "edit")
}
</code></pre>
<p dir="auto">However, the <code>TextField</code> ends up with the display role data instead. I started print debugging this (I'm using Rust, hopefully this is simple enough code to understand for C++ programmers):</p>
<pre><code class="language-rs">fn data(&amp;self, index: &amp;QModelIndex, role: i32) -&gt; QVariant {
    println!("{role}");
    // ...
}
</code></pre>
<p dir="auto">It prints out 0, the display role, never 2, the edit role.</p>
<p dir="auto">I didn't override <code>roleNames</code>, so <code>edit</code> name should be bound to the edit role, but just in case, I tried setting my own too:</p>
<pre><code class="language-rs">// role_names is equivalent to roleNames in C++
fn role_names(&amp;self) -&gt; QHash&lt;QHashPair_i32_QByteArray&gt; {
    let mut role_names = QHash::default();
    role_names.insert(ItemDataRole::DisplayRole.repr, QByteArray::from("display".as_bytes()));
    role_names.insert(ItemDataRole::EditRole.repr, QByteArray::from("edit".as_bytes()));
    role_names
}
</code></pre>
<p dir="auto">This did not change anything.</p>
<p dir="auto">What could be the issue here?</p>
]]></description><link>https://forum.qt.io/topic/165250/calling-the-data-method-of-a-qabstractitemmodel-in-qml-always-uses-display-role-instead-of-the-requested-role</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 21:07:05 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/165250.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 07 Nov 2026 12:53:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Calling the data method of a QAbstractItemModel in QML always uses display role instead of the requested role on Sat, 07 Nov 2026 20:35:07 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">Might be a silly question but are you using Qt Bridges ?</p>
]]></description><link>https://forum.qt.io/post/840832</link><guid isPermaLink="true">https://forum.qt.io/post/840832</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 07 Nov 2026 20:35:07 GMT</pubDate></item></channel></rss>