Hi..
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,
- code is compiling fine but it will give some linker error,
- I tried the same code by keeping different header files, it runs well, but i am not getting control to my delegate class only.
Please can you suggest what the mistake(s) might be?
#include <QtGui>
#include <QApplication>
#include <QtGui/QMainWindow>
class ItemDeligate:public QStyledItemDelegate
{
public:
ItemDeligate(QObject *parent = 0):QStyledItemDelegate(parent)
{}
~ItemDeligate(){}
public:
enum ItemDataRole { SubTextRole = Qt::UserRole + 100};
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
};
QSize ItemDeligate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
//here i know implimentation
}
void ItemDeligate::paint(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &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<QStandardItem *> 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->geometry();
MylistView->setMinimumSize(QSize(clientRect.width()-7,clientRect.height()-1));
MylistView->setViewMode(QListView::ListMode);
MylistView->setMovement(QListView::Free);
MylistView->setItemDelegate(new ItemDeligate(MylistView));
MylistView->setSelectionMode(QAbstractItemView::SingleSelection);
bool val =GreenPixmap.load(":/new/prefix1/temp/test.png");
ListModel = new QStandardItemModel();
ListModel->appendColumn(ItemList);
MylistView->setModel(ListModel);
Listlayout.addWidget(MylistView);
Listlayout.addWidget(MylistView);
this->setLayout(&Listlayout);
AddItemMenu = new QAction("Add",this);
menuBar()->addAction(AddItemMenu);
val = connect(AddItemMenu,SIGNAL(triggered()),this,SLOT(addItem()));
}
void Test::addItem()
{
QStandardItem *Items = new QStandardItem(QIcon(GreenPixmap),"Avatar");
Items->setData("WAKE UP",ItemDeligate::SubTextRole);
ItemList.append(Items);
ListModel->appendColumn(ItemList);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Test test;
test.showMaximized();
test.showMaximized();
return a.exec();
}
Errors caused tool to abort.
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