这是我的第一个QT问题 - 我一般是一个C#程序员,所以原谅我问一个愚蠢的问题,我相信有一个非常简单的答案,我只是不能找到:
This is my first QT question - I'm generally a C# programmer so forgive me for asking a stupid question for which I'm sure there's a very simple answer, which I just can't seem to find:
我想向列表中添加项目,暂时假设它们是字符串。 我有一个QListView: UI-> listView ,一个QStringList和一个QStringListModel:
I want to add items to a list, for the moment let's say they're strings. I have a QListView: UI->listView, a QStringList, and a QStringListModel:
stringList = new QStringList(); stringList->append("ABC"); stringList->append("123"); listModel = new QStringListModel(*stringList, NULL); ui->listView->setModel(listModel); stringList->append("xyz");此示例在我的列表中编译和废弃ABC和123,但不是xyz 。为什么不?我需要重新绘制listView不知何故?我做了错误的NULL?
This example compiles and disaplys "ABC" and "123" in my list, but not "xyz". Why not? Do I need to repaint the listView somehow? Have I done something wrong with the NULL?
谢谢。
推荐答案您已修改 QStringList ,您需要修改模型:
You've modified the QStringList, you need to modify the model:
stringList->append("xyz"); listModel->setStringList(*stringList);更多推荐
QT4 QstringListModel在QListView
发布评论