Results 1 to 4 of 4

Thread: Error in Qlistmodel standard item

  1. #1
    Join Date
    Mar 2011
    Posts
    51
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Error in Qlistmodel standard item

    hello every one i want to make list in Qt having 3 column i have made code but its not working kindly have a look at it


    Qt Code:
    1. QStandardItemModel *listmodel = new QStandardItemModel(this);
    2. QStandardItem * root = listmodel->invisibleRootItem();
    3. QStandardItem *item = new QStandardItem("col1" ,"col2" ,"col3");
    4. root->appendRow(item);
    To copy to clipboard, switch view to plain text mode 

    i am getting an error at 3rd line kindly tell me how to add columns in list box

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Error in Qlistmodel standard item

    If you need columns in your list, then you should use table (not list), list is always one column.

    Start exploring use of QTableView

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Error in Qlistmodel standard item

    You get that error because there is no c-tor like you which there were. Further it is more a table than a list you are creating. Have a look at QStandardItemModel and the first example in the detailed description is what you are looking for.

  4. #4
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Error in Qlistmodel standard item

    You can also fix your code:

    Qt Code:
    1. QStandardItemModel *listmodel = new QStandardItemModel(this);
    2. QStandardItem * root = listmodel->invisibleRootItem();
    3. QList<QStandardItem *> row;
    4. row << new QStandardItem("col1") << new QStandardItem("col2") << new QStandardItem("col3") ;
    5. root->appendRow(row);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 7
    Last Post: 3rd December 2010, 05:02
  2. standard QT libraies
    By GrahamLabdon in forum Newbie
    Replies: 2
    Last Post: 21st October 2010, 12:37
  3. Choice between Standard- and Abstract Item Model
    By hunsrus in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2009, 15:14
  4. Replies: 2
    Last Post: 2nd June 2008, 08:45
  5. QProcess +standard error + windows
    By antonio.r.tome in forum Qt Programming
    Replies: 0
    Last Post: 18th April 2006, 14:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.