Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere is the mistake in my code?
    text
    copied!<p>I want to make a customized list view, in that I will add items dynamically, I have written code for the same, but it's giving me some problems,</p> <ol> <li>code is compiling fine but it will give some linker error,</li> <li>I tried the same code by keeping different header files, it runs well, but i am not getting control to my delegate class only.</li> </ol> <p>Please can you suggest what the mistake(s) might be?</p> <pre><code>#include &lt;QtGui&gt; #include &lt;QApplication&gt; #include &lt;QtGui/QMainWindow&gt; class ItemDeligate:public QStyledItemDelegate { public: ItemDeligate(QObject *parent = 0):QStyledItemDelegate(parent) { } ~ItemDeligate() { } public: enum ItemDataRole { SubTextRole = Qt::UserRole + 100 }; QSize sizeHint( const QStyleOptionViewItem&amp; option, const QModelIndex&amp; index ) const; void paint( QPainter* painter, const QStyleOptionViewItem&amp; option, const QModelIndex&amp; index ) const; }; QSize ItemDeligate::sizeHint( const QStyleOptionViewItem&amp; option, const QModelIndex &amp;index) const { // here i know implimentation } void ItemDeligate::paint( QPainter* p, const QStyleOptionViewItem&amp; option, const QModelIndex&amp; index ) const { // here i know the implimentation QStyledItemDelegate::paint(p,option,index); } class Test : public QMainWindow { Q_OBJECT public: Test(QWidget *parent = 0); ~Test() { } QPixmap GreenPixmap; QList&lt;QStandardItem *&gt; ItemList; QStandardItemModel *ListModel; QVBoxLayout Listlayout; QListView *MylistView; QAction *AddItemMenu; public slots: void addItem(); }; Test::Test(QWidget *parent) : QMainWindow(parent) { MylistView = new QListView(); QDesktopWidget* desktopWidget = QApplication::desktop(); QRect clientRect = desktopWidget-&gt;geometry(); MylistView-&gt;setMinimumSize( QSize( clientRect.width() - 7, clientRect.height() - 1 ) ); MylistView-&gt;setViewMode(QListView::ListMode); MylistView-&gt;setMovement(QListView::Free); MylistView-&gt;setItemDelegate(new ItemDeligate(MylistView)); MylistView-&gt;setSelectionMode(QAbstractItemView::SingleSelection); bool val = GreenPixmap.load(":/new/prefix1/temp/test.png"); ListModel = new QStandardItemModel(); ListModel-&gt;appendColumn(ItemList); MylistView-&gt;setModel(ListModel); Listlayout.addWidget(MylistView); Listlayout.addWidget(MylistView); this-&gt;setLayout(&amp;Listlayout); AddItemMenu = new QAction("Add",this); menuBar()-&gt;addAction(AddItemMenu); val = connect(AddItemMenu,SIGNAL(triggered()),this,SLOT(addItem())); } void Test::addItem() { QStandardItem *Items = new QStandardItem(QIcon(GreenPixmap),"Avatar"); Items-&gt;setData("WAKE UP",ItemDeligate::SubTextRole); ItemList.append(Items); ListModel-&gt;appendColumn(ItemList); } int main(int argc, char *argv[]) { QApplication a(argc, argv); Test test; test.showMaximized(); test.showMaximized(); return a.exec(); } </code></pre> <p>Errors caused tool to abort.</p> <blockquote> <p>mwldsym2.exe: Undefined symbol: 'void * Test::qt_metacast(char const *) (?qt_metacast@Test@@UAEPAXPBD@Z)' mwldsym2.exe: referenced from 'const Test::vftable' (??_7Test@@6B@~)' in main.o mwldsym2.exe: Undefined symbol: 'struct QMetaObject const * Test::metaObject(void) const (?metaObject@Test@@UBEPBUQMetaObject@@XZ)' mwldsym2.exe: referenced from 'const Test::`vftable' (??_7Test@@6B@~)' in main.o</p> </blockquote>
 

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