PDA

View Full Version : problem with QListView



penny
3rd January 2011, 06:49
i have written the following code, for QListView, and now i want to add data to the QListView. But the addColumn method is giving an error,

'addColumn' : is not a member of 'QListView'

Also, there is a "syntax error : identifier QListViewItem"

this is my code:
QListView *list = new QListView(this);
list->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
list->addColumn("name");
list->setAllColumnsShowFocus(true);
new QListViewItem(list,"myname1");


I have included qlistview.h..

ChrisW67
3rd January 2011, 07:00
'addColumn' : is not a member of 'QListView'
Q3ListView::addColumn(), Q3ListView::setAllColumnsShowFocus() and Q3ListViewItem are part of the Qt4 support for porting from Qt3. Looks like you have code for Qt3 but a Qt4 dev environment. Are you programming for Qt3 or Qt4?

Please use [code] tags around your code snippets. (You can edit your first post to add them)

penny
3rd January 2011, 09:32
I'm using Qt4.. So which file do i need to include? The qlistview.h file doesn't have definitions of addColumn and setAllColumnsShowFocus.

BalaQT
3rd January 2011, 10:03
hi,
u want one column or more columns?
Bala

penny
3rd January 2011, 10:21
I want only one column

squidge
3rd January 2011, 10:50
What you have will only work on Qt3 (or the QT3 support for QT4). You will need to port your code to QT4.

ChrisW67
3rd January 2011, 21:34
You need to use QListView or QListWidget. The way these are populated has changed since Qt3 though, so you will have to modify your code to match Qt4.

If you continue to use QListView then you need to create a model of some sort to provide the data. This model is where you will find the equivalent of addColumn(). If you use QListWidget then the API is a little closer to what your code is expecting.

Either way you must read "Model/View Programming" in Assistant.