<?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[Unresolved external symbol when launching Qt&#x27;s example]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm trying to run example from Qt <a href="https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">documentation</a> about <code>QTreeView</code>.<br />
I copied two classes:<br />
<strong>treeitem.h</strong></p>
<pre><code>#ifndef TREEITEM_H
#define TREEITEM_H

#include &lt;QtCore&gt;

class TreeItem
{
public:
    explicit TreeItem(const QVector&lt;QVariant&gt; &amp;data, TreeItem *parentItem = nullptr);
    ~TreeItem();

    void appendChild(TreeItem *child);

    TreeItem *child(int row);
    int childCount() const;
    int columnCount() const;
    QVariant data(int column) const;
    int row() const;
    TreeItem *parentItem();

private:
    QVector&lt;TreeItem*&gt; m_childItems;
    QVector&lt;QVariant&gt; m_itemData;
    TreeItem *m_parentItem;
};

#endif // TREEITEM_H

</code></pre>
<p dir="auto"><strong>treeitem.cpp</strong></p>
<pre><code>#include "treeitem.h"

TreeItem::TreeItem(const QVector&lt;QVariant&gt; &amp;data, TreeItem *parent)
    : m_itemData(data), m_parentItem(parent)
{

}

TreeItem::~TreeItem()
{
    qDeleteAll(m_childItems);
}

void TreeItem::appendChild(TreeItem *item)
{
    m_childItems.append(item);
}

TreeItem *TreeItem::child(int row)
{
    if (row &lt; 0 || row &gt;= m_childItems.size())
        return nullptr;
    return m_childItems.at(row);
}

int TreeItem::childCount() const
{
    return m_childItems.count();
}

int TreeItem::row() const
{
    if (m_parentItem)
        return m_parentItem-&gt;m_childItems.indexOf(const_cast&lt;TreeItem*&gt;(this));

    return 0;
}
</code></pre>
<p dir="auto">And the seond class:<br />
<strong>treemodel.h</strong></p>
<pre><code>#ifndef TREEMODEL_H
#define TREEMODEL_H

#include &lt;QtCore&gt;
#include &lt;treeitem.h&gt;


class TreeModel : public QAbstractItemModel
{
    Q_OBJECT

public:
    explicit TreeModel(const QString &amp;data, QObject *parent = nullptr);
    ~TreeModel();

    QVariant data(const QModelIndex &amp;index, int role) const override;
    Qt::ItemFlags flags(const QModelIndex &amp;index) const override;
    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const override;
    QModelIndex index(int row, int column,
                      const QModelIndex &amp;parent = QModelIndex()) const override;
    QModelIndex parent(const QModelIndex &amp;index) const override;
    int rowCount(const QModelIndex &amp;parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &amp;parent = QModelIndex()) const override;

private:
    void setupModelData(const QStringList &amp;lines, TreeItem *parent);

    TreeItem *rootItem;
};

#endif // TREEMODEL_H

</code></pre>
<p dir="auto"><strong>treemodel.cpp</strong></p>
<pre><code>#include "treemodel.h"

TreeModel::TreeModel(const QString &amp;data, QObject *parent)
    : QAbstractItemModel(parent)
{
    rootItem = new TreeItem({tr("Title"), tr("Summary")});
    setupModelData(data.split('\n'), rootItem);
}

TreeModel::~TreeModel()
{
    delete rootItem;
}

QModelIndex TreeModel::index(int row, int column, const QModelIndex &amp;parent) const
{
    if (!hasIndex(row, column, parent))
        return QModelIndex();

    TreeItem *parentItem;

    if (!parent.isValid())
        parentItem = rootItem;
    else
        parentItem = static_cast&lt;TreeItem*&gt;(parent.internalPointer());

    TreeItem *childItem = parentItem-&gt;child(row);
    if (childItem)
        return createIndex(row, column, childItem);
    return QModelIndex();
}

QModelIndex TreeModel::parent(const QModelIndex &amp;index) const
{
    if (!index.isValid())
        return QModelIndex();

    TreeItem *childItem = static_cast&lt;TreeItem*&gt;(index.internalPointer());
    TreeItem *parentItem = childItem-&gt;parentItem();

    if (parentItem == rootItem)
        return QModelIndex();

    return createIndex(parentItem-&gt;row(), 0, parentItem);
}

int TreeModel::rowCount(const QModelIndex &amp;parent) const
{
    TreeItem *parentItem;
    if (parent.column() &gt; 0)
        return 0;

    if (!parent.isValid())
        parentItem = rootItem;
    else
        parentItem = static_cast&lt;TreeItem*&gt;(parent.internalPointer());

    return parentItem-&gt;childCount();
}

int TreeModel::columnCount(const QModelIndex &amp;parent) const
{
    if (parent.isValid())
        return static_cast&lt;TreeItem*&gt;(parent.internalPointer())-&gt;columnCount();
    return rootItem-&gt;columnCount();
}

QVariant TreeModel::data(const QModelIndex &amp;index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (role != Qt::DisplayRole)
        return QVariant();

    TreeItem *item = static_cast&lt;TreeItem*&gt;(index.internalPointer());

    return item-&gt;data(index.column());
}

Qt::ItemFlags TreeModel::flags(const QModelIndex &amp;index) const
{
    if (!index.isValid())
        return Qt::NoItemFlags;

    return QAbstractItemModel::flags(index);
}

QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
                               int role) const
{
    if (orientation == Qt::Horizontal &amp;&amp; role == Qt::DisplayRole)
        return rootItem-&gt;data(section);

    return QVariant();
}
</code></pre>
<p dir="auto">If I add those file to the Qt project then I get the following errors when the app is building:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/0cc9e51a-1922-4e2f-a08a-068da10ca5e7.png" alt="1.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">How to launch this example?</p>
]]></description><link>https://forum.qt.io/topic/114881/unresolved-external-symbol-when-launching-qt-s-example</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 19:10:04 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/114881.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 16 May 2020 16:05:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unresolved external symbol when launching Qt&#x27;s example on Sat, 16 May 2020 16:33:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/please_help_me_d">@<bdi>Please_Help_me_D</bdi></a> said in <a href="/post/595122">Unresolved external symbol when launching Qt's example</a>:</p>
<blockquote>
<p dir="auto">How to launch this example?</p>
</blockquote>
<p dir="auto">By simple don't forget to implement those functions (or copy them over) ...</p>
]]></description><link>https://forum.qt.io/post/595126</link><guid isPermaLink="true">https://forum.qt.io/post/595126</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 16 May 2020 16:33:19 GMT</pubDate></item><item><title><![CDATA[Reply to Unresolved external symbol when launching Qt&#x27;s example on Sat, 16 May 2020 20:28:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> thank you a lot :)</p>
]]></description><link>https://forum.qt.io/post/595165</link><guid isPermaLink="true">https://forum.qt.io/post/595165</guid><dc:creator><![CDATA[Please_Help_me_D]]></dc:creator><pubDate>Sat, 16 May 2020 20:28:07 GMT</pubDate></item><item><title><![CDATA[Reply to Unresolved external symbol when launching Qt&#x27;s example on Sat, 16 May 2020 19:56:42 GMT]]></title><description><![CDATA[<p dir="auto">The complete <a href="https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/itemviews/simpletreemodel?h=5.14" target="_blank" rel="noopener noreferrer nofollow ugc">code is linked</a> to at the bottom of the page of the documentation.</p>
]]></description><link>https://forum.qt.io/post/595158</link><guid isPermaLink="true">https://forum.qt.io/post/595158</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 16 May 2020 19:56:42 GMT</pubDate></item><item><title><![CDATA[Reply to Unresolved external symbol when launching Qt&#x27;s example on Sat, 16 May 2020 19:38:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> really? I can only see the declaration inside <code>class TreeModel</code>:</p>
<pre><code>void setupModelData(const QStringList &amp;lines, TreeItem *parent);
</code></pre>
]]></description><link>https://forum.qt.io/post/595155</link><guid isPermaLink="true">https://forum.qt.io/post/595155</guid><dc:creator><![CDATA[Please_Help_me_D]]></dc:creator><pubDate>Sat, 16 May 2020 19:38:31 GMT</pubDate></item><item><title><![CDATA[Reply to Unresolved external symbol when launching Qt&#x27;s example on Sat, 16 May 2020 19:11:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/please_help_me_d">@<bdi>Please_Help_me_D</bdi></a> The code is there in the documentation.</p>
]]></description><link>https://forum.qt.io/post/595147</link><guid isPermaLink="true">https://forum.qt.io/post/595147</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 16 May 2020 19:11:56 GMT</pubDate></item><item><title><![CDATA[Reply to Unresolved external symbol when launching Qt&#x27;s example on Sat, 16 May 2020 18:17:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> thank you! that helped<br />
The only thing that left to do is to understand how to implement <code>TreeModel::setupModelData()</code></p>
]]></description><link>https://forum.qt.io/post/595140</link><guid isPermaLink="true">https://forum.qt.io/post/595140</guid><dc:creator><![CDATA[Please_Help_me_D]]></dc:creator><pubDate>Sat, 16 May 2020 18:17:26 GMT</pubDate></item><item><title><![CDATA[Reply to Unresolved external symbol when launching Qt&#x27;s example on Sat, 16 May 2020 16:33:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/please_help_me_d">@<bdi>Please_Help_me_D</bdi></a> said in <a href="/post/595122">Unresolved external symbol when launching Qt's example</a>:</p>
<blockquote>
<p dir="auto">How to launch this example?</p>
</blockquote>
<p dir="auto">By simple don't forget to implement those functions (or copy them over) ...</p>
]]></description><link>https://forum.qt.io/post/595126</link><guid isPermaLink="true">https://forum.qt.io/post/595126</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 16 May 2020 16:33:19 GMT</pubDate></item></channel></rss>