Results 1 to 11 of 11

Thread: set XML tag to QTableView

  1. #1
    Join Date
    Mar 2013
    Posts
    43
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default set XML tag to QTableView

    Hi,
    I am having an XML file which containing titles and authors of books. I am reading the title tags alone and I want to display them in QTableView in rows. Please help me.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: set XML tag to QTableView

    What is the problem you are having?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2013
    Posts
    43
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: set XML tag to QTableView

    I am using QStandardItemModel and QModelIndex. When I am inserting rows, the rows should be appended to the existing rows not to be inserted before the existing rows

    my code is
    QStandardItemModel *model = new QStandardItemModel();
    QModelIndex parentItem;
    QModelIndex mindex;
    After reading the 'title' tag from XML , I am assigning the text to a variable "text" of type QSting.

    parentItem = model->index(row, 0, parentItem);
    model->insertRows(0, 1, parentItem);
    mindex=model->index(0,0);
    model->setData(mindex,text);

    Please help me.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: set XML tag to QTableView

    This problem has nothing to do with the view.

    If you do not want to insert the row at the front of the model rows then do not call insertRow(0,...). You want to insert the new row before the (non-existent) row rowCount():
    Qt Code:
    1. model->insertRow(model->rowCount(parentIndex), parentIndex);
    To copy to clipboard, switch view to plain text mode 

    There are other problems:
    • Your thread title implies you are expecting a table structure but you appear to be trying to build a tree.
    • You also set the text on the-most top-level item every time; not the item you just inserted.
    • Have you called insertColumn() or setColumnCount() at some stage? Otherwise your model has no columns.


    I think, in general, you need to read the QStandardItemModel Detailed Description for examples of creating a table.

  5. #5
    Join Date
    Mar 2013
    Posts
    43
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: set XML tag to QTableView

    Yes, what u said is correct. I dont want tree structure. I want just table. I have set the Column count to 1. Only problem I am facing is its appending rows. Can u give me the lines of code for tableView without parentitem.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: set XML tag to QTableView

    Quote Originally Posted by mythili View Post
    I dont want tree structure. I want just table. I have set the Column count to 1.
    So you don't want a table but rather a list.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2013
    Posts
    43
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: set XML tag to QTableView

    Can u give me the lines of code for listView or tableView using QStandardItremModel and QModelIndex

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: set XML tag to QTableView

    Docs for QStandardItemModel contain an example for building a tree or a table.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Mar 2013
    Posts
    43
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: set XML tag to QTableView

    I want to use QModelIndex instead of QStandardItem. Can u help me

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: set XML tag to QTableView

    Qt Code:
    1. model.insertRow(model.rowCount());
    2. QModelIndex idx = model.index(model.rowCount()-1);
    3. model.setData(idx, "foo", Qt::DisplayRole);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Mar 2013
    Posts
    43
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: set XML tag to QTableView

    Thank u very much..Its working fine...
    Last edited by mythili; 7th May 2013 at 13:45.

Similar Threads

  1. QTableView and QLineEdit OUTSIDE of QTableView, like Excel
    By JoZCaVaLLo in forum Qt Programming
    Replies: 10
    Last Post: 13th May 2011, 13:20
  2. Replies: 2
    Last Post: 26th November 2009, 04:45
  3. QTableView
    By jamesjara in forum Newbie
    Replies: 5
    Last Post: 26th June 2009, 06:37
  4. QTableView
    By fpujol in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2007, 08:17

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.