Results 1 to 2 of 2

Thread: Data from model not inserted in QTableView

  1. #1
    Join Date
    Jul 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default Data from model not inserted in QTableView

    I am trying to insert some data in a TableView from a model but I am doing something wrong because the data is not inserted. The table is updated with the columns and rows though.

    So I have a GraphicsView where I am drawing some custom GraphicsItems. Each time a new Item is added to the scene the model is supposed to get updated and send a signal to my TableView to insert the data in it as well.

    Here I update the model when the new item is added:

    Qt Code:
    1. Clothoid *temp = new Clothoid();
    2. temp->setStartPoint(p1);
    3. temp->setEndPoint(p2);
    4.  
    5. clothoids.append(temp);
    6.  
    7. scene->addItem(temp);
    8.  
    9. model.setColumnCount(3);
    10. model.setRowCount(clothoids.size());
    11.  
    12. QModelIndex index = model.index(clothoids.size(), 1, QModelIndex());
    13. model.setData(index, clothoids.last()->startCurvature);
    14. index = model.index(clothoids.size(), 2, QModelIndex());
    15. model.setData(index, clothoids.last()->endCurvature);
    16. index = model.index(clothoids.size(), 3, QModelIndex());
    17. model.setData(index, clothoids.last()->clothoidLength);
    18.  
    19. emit clothoidAdded(&model);
    To copy to clipboard, switch view to plain text mode 

    Clothoids being a list of my custom graphicsItems:

    Qt Code:
    1. QList < Clothoid *> clothoids;
    To copy to clipboard, switch view to plain text mode 

    The signal is connected to the slot in my main window:

    Qt Code:
    1. ui->setupUi(this);
    2. SpinBoxDelegate delegate;
    3. ui->clothoidTable->setItemDelegate(&delegate);
    4.  
    5. connect(ui->graphicsView, SIGNAL(clothoidAdded(QStandardItemModel*)), ui->clothoidTable, SLOT(onClothoidAdded(QStandardItemModel*)));
    To copy to clipboard, switch view to plain text mode 

    where the slot is:

    Qt Code:
    1. void TableViewList::onClothoidAdded(QStandardItemModel *model)
    2. {
    3. setModel(model);
    4. }
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong?

  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: Data from model not inserted in QTableView

    What is model? did you implement it, are the index item editable, is editable flag set.

    moreover column index should be 0,1,2 (not 1,2,3), and row index should be clothoids.size() - 1 (not clothoids.size())

Similar Threads

  1. Replies: 1
    Last Post: 24th February 2011, 05:54
  2. How to fill an inserted column with data?
    By croo in forum Qt Programming
    Replies: 3
    Last Post: 12th December 2010, 19:58
  3. QTableView massive model data updates issue
    By cyberbob in forum Newbie
    Replies: 3
    Last Post: 7th December 2010, 23:09
  4. Replies: 1
    Last Post: 15th October 2010, 22:30
  5. Model/View framework: streaming data in a QTableView
    By yannickt in forum Qt Programming
    Replies: 6
    Last Post: 24th October 2008, 00:06

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.