How to access childWidgets in a QTreeView using QModelIndex?
<p>I'm working on an application using the Qt library (version 4.8).</p>

<p>I have a QTreeView with a QStandardItemModel. My widget looks like that:</p>

<blockquote>
  <p>Item1</p>
  
  <p>subitem11</p>
  
  <p>subitem12</p>
  
  <p>Item2</p>
  
  <p>subitem21</p>
  
  <p>subitem22</p>
  
  <p>Item3</p>
  
  <p>subitem31</p>
  
  <p>subitem32</p>
</blockquote>

<p>Here is how I add the items to my QTreeView:</p>

<pre><code> model-&gt;setItem(0, 0, item1); 
 item1-&gt;setChild(0, 0, subitem12);
</code></pre>

<p>I want to take an action only when the user double cliked an item (and do nothing when he clicked a subitem). So I use the  <em>doubleClicked(const QModelIndex &amp; index)</em> signal. </p>

<p>I want to process the information about the item/subitem which was double cliked by the user. So I get the row of my item/subitem:</p>

<pre><code>index.row();
</code></pre>

<p>But every time I try to reference to the item/subitem to display its name or check if it has children, I can only access the items:</p>

<pre><code>index.model()-&gt;item(row)-&gt;text();
</code></pre>

<p>My question is: how can I acces the subitems (vbetween items abd subitems) in my slot? Or how can I prevent them from emitting the signal? I can't disable them - it would be too confusing for the user. </p>

<p><strong>Edit:</strong> The problem is that every time I click on an item or subitem and execute:</p>

<pre><code>index.model()-&gt;item(row)-&gt;hasChildren();
</code></pre>

<p>or:</p>

<pre><code>index.model()-&gt;item(row)-&gt;parent() == 0;
</code></pre>

<p>I get <em>true</em> as result. So I can reference only the items. </p>

<p>My question is: <strong>What is the correct way to reference to subitems?</strong></p>