<?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[[SOLVED] QListView remains empty]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">Please can anyone help. My QListView remains empty, while my model is OK.<br />
If I set a breakpoint in "data()", it doesn't get reached.</p>
<p dir="auto">Thank you,</p>
<p dir="auto">@<br />
// standard constructor</p>
<p dir="auto">// standard destructor</p>
<p dir="auto">// rowCount is OK<br />
int DicomImageModel::rowCount(const QModelIndex &amp; /<em>parent</em>/) const<br />
{<br />
int i = getImagesCount();<br />
xLogWarning(XLogRecord::Type_User, QString("'rowCount' called, value: %1").arg(i));<br />
return i;<br />
}</p>
<p dir="auto">// fixed size, do I need to add headers or would it work without?<br />
int DicomImageModel::columnCount(const QModelIndex &amp; /<em>parent</em>/) const<br />
{<br />
return 6;<br />
}</p>
<p dir="auto">// data... don't log here<br />
QVariant DicomImageModel::data(const QModelIndex &amp;index, int role) const<br />
{<br />
xLogWarning(XLogRecord::Type_User, QString("'data' called"));</p>
<pre><code> int row = index.row();
 int col = index.column();
 // generate a log message when this method gets called
 xLogWarning(XLogRecord::Type_User, QString("row %1, col%2, role %3").arg(row).arg(col).arg(role));

 //xLogWarning(XLogRecord::Type_User, QString(m_dicomImages[0]-&gt;getId()));

 if(role == Qt::DisplayRole){
     if (col == 0) return QString(m_dicomImages[row]-&gt;getId());
     //if (col == 1) return QString(m_dicomImages[row]-&gt;getDicomRef().getSeriesInstanceUID());

     return QString("Row%1, Column%2")
             .arg(row + 1)
             .arg(col + 1);
 }

 return QString("Row%1, Column%2")
         .arg(row + 1)
         .arg(col + 1);

 return QVariant();
</code></pre>
<p dir="auto">}</p>
<p dir="auto">// populate model, seems ok but I have no "view" of what happens.<br />
void DicomImageModel::addImage(const XImageObjectPtr image)<br />
{<br />
int nbRows = m_dicomImages.size();<br />
beginInsertRows(QModelIndex(), nbRows, nbRows);<br />
m_dicomImages.push_back(image);<br />
xLogWarning(XLogRecord::Type_User, QString(tr("Image %1 added").arg(image-&gt;getId())));<br />
endInsertRows();<br />
}</p>
<p dir="auto">// just a helper, m_dicomImages is a vector of shared pointers (QSharedPointer).<br />
int DicomImageModel::getImagesCount() const {<br />
return m_dicomImages.size();<br />
}<br />
@</p>
]]></description><link>https://forum.qt.io/topic/37984/solved-qlistview-remains-empty</link><generator>RSS for Node</generator><lastBuildDate>Sat, 08 Aug 2026 18:44:05 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/37984.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Feb 2014 13:55:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] QListView remains empty on Wed, 19 Feb 2014 11:21:02 GMT]]></title><description><![CDATA[<p dir="auto">I found the problem: I was reinstantiating the model, since I fixed code but not totally by moving the model declaration to the header. Once fixed I have data as expected.</p>
]]></description><link>https://forum.qt.io/post/215458</link><guid isPermaLink="true">https://forum.qt.io/post/215458</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 19 Feb 2014 11:21:02 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QListView remains empty on Tue, 18 Feb 2014 20:38:50 GMT]]></title><description><![CDATA[<p dir="auto">it should:</p>
<p dir="auto">@return QAbstractTableModel::data(index, role);@</p>
<p dir="auto">The row/column count are not constantly queried. Only when you notify the view that the model has changed.</p>
<p dir="auto">I would recommend that you have a look at the various Model View examples from Qt's documentation. You'll learn how things work with it</p>
]]></description><link>https://forum.qt.io/post/215361</link><guid isPermaLink="true">https://forum.qt.io/post/215361</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 18 Feb 2014 20:38:50 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QListView remains empty on Tue, 18 Feb 2014 14:47:25 GMT]]></title><description><![CDATA[<p dir="auto">DicomImageModel derive from QAbstractTableModel.</p>
<p dir="auto">I'm a beginner, so what should I return when it's not a DisplayRole? I lately added this, in fact.</p>
<p dir="auto">The small plugin I use gets instantiated when I open the main GUI, then if I click on a menu item it gets enabled (visible). It contains a QListView with model previously described.</p>
<p dir="auto">Something is wrong with rowCount() and columnCount(), they're called at startup, when plugin and model are instantiated, then...</p>
<p dir="auto">When I add an image to model, rowCount() gets called, but shows "0 row", then I have "1 object in model". It's always 1 item behind.</p>
<p dir="auto">When I then click onto menu item link, my widget shows, but neither rowCount() nor columnCount() get called again...</p>
]]></description><link>https://forum.qt.io/post/215318</link><guid isPermaLink="true">https://forum.qt.io/post/215318</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 18 Feb 2014 14:47:25 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QListView remains empty on Tue, 18 Feb 2014 14:38:25 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">What is your DicomImageModel for a class ?</p>
<p dir="auto">Why do you return an empty QVariant for everything that is not DisplayRole ?</p>
]]></description><link>https://forum.qt.io/post/215316</link><guid isPermaLink="true">https://forum.qt.io/post/215316</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 18 Feb 2014 14:38:25 GMT</pubDate></item></channel></rss>