Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to do this in two separate classes because Qt's extensions to c++ (SIGNALS, SLOTS, etc.) do not play well with templates. The rationale and workaround for this can be found at: <a href="http://doc.qt.digia.com/qq/qq15-academic.html" rel="nofollow">http://doc.qt.digia.com/qq/qq15-academic.html</a></p> <p>Here is a rough outline of a solution. (This is based on code we are using in our application and that is working fine.)</p> <p><strong>1. Abstract list class that does Qt stuff</strong></p> <pre><code>class FooListModelQt : public QAbstractTableModel { Q_OBJECT public: // Non-template methods, signals, slots, etc. can be used here. For example... QSet&lt;int&gt; SelectedRows() const; // ... etc. ... signals: void SelectionChanged(); // ... etc. ... protected: explicit FooListModelQt(QObject *parent = NULL); virtual ~FooListModelQt() = 0; // ... etc. ... }; </code></pre> <p><strong>2. Abstract class that does template stuff</strong></p> <pre><code>template &lt;typename T&gt; class FooListModel : public FooListModelQt { public: const T* at(int index) const { return items_.at(index); } int count() const { return items_.count(); } void Append(T *item); // ... etc. ... protected: explicit FooListModel(QObject *parent = NULL); virtual ~FooListModel(); private: QList&lt;T*&gt; items_; }; </code></pre> <p><strong>3. Actual list class</strong></p> <pre><code>class BarListModel : public FooListModel&lt;Bar&gt; { Q_OBJECT public: explicit BarListModel(QObject *parent = NULL); int columnCount(const QModelIndex &amp;parent) const; QVariant data(const QModelIndex &amp;index, int role) const; // ... etc. ... }; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload