Results 1 to 5 of 5

Thread: QStringListModel doesn't update when QStringList is updated

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2013
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default QStringListModel doesn't update when QStringList is updated

    Hi,
    I would like help about these points
    1/ I want to use the append in my method so i can add "Belgique" for ex. to my list but when i do like this nothing happens when i push the button Add....this my code and window new.jpg
    Qt Code:
    1. #include"scheduletable.h"
    2.  
    3. #include "ui_scheduletable.h"
    4. #include<QStringListModel>
    5. ScheduleTable::ScheduleTable(QWidget*parent):
    6. QWidget(parent),
    7. ui(newUi::ScheduleTable)
    8. {
    9. ui->setupUi(this);
    10. QStringListlistePays;
    11. listePays<<"France";
    12. QStringListModel*modele=newQStringListModel(listePays);
    13. ui->listView->setModel(modele);
    14. connect(ui->addFrame,SIGNAL(clicked()),this,SLOT(add_Frame()));
    15. }
    16. voidScheduleTable::add_Frame()
    17. {
    18. listePays.append("Belgique");
    19.  
    20. }
    21. ScheduleTable::~ScheduleTable()
    22. {
    23. deleteui;
    24. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Qt 5.0.1

    QStringListModel stores a copy of the string list you pass it. Thus if you add a new entry to the original string list, the model does not get updated. Since QStringListModel is read-only, the only solution is to set a new string list on it again but then you'll lose things such as selection and scrolling in the view because the model will be reset. A more proper solution would be to use QStandardItemModel and add a new entry directly to the model with QStandardItemModel::appendRow().
    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.


Similar Threads

  1. GUI doesn't update in QThreaded opengl application
    By bingofuel in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2012, 08:04
  2. QDataWidgetMapper doesn't always update field in table
    By marcvanriet in forum Qt Programming
    Replies: 4
    Last Post: 14th December 2011, 11:57
  3. QGraphicsScene's sceneRect() doesn't update
    By blooglet in forum Qt Programming
    Replies: 2
    Last Post: 17th February 2011, 09:11
  4. QGLWidget doesn't update
    By qtbnl in forum Qt Programming
    Replies: 12
    Last Post: 14th February 2011, 17:41
  5. QComboBox doesn't update when on hidden widget
    By martinb0820 in forum Qt Programming
    Replies: 1
    Last Post: 10th December 2010, 22:09

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.