QT4 QstringListModel在QListView

编程入门 行业动态 更新时间:2024-10-23 03:28:53
本文介绍了QT4 QstringListModel在QListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的第一个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

本文发布于:2023-10-09 18:25:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476437.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:QstringListModel   QListView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!