信号发出问题-列表视图没有显示完整的列表
Signal emit Issue - Listview is not showing full list
我绑定了一个ListView与值从cpp传递。
问题:Listview只显示一行,平均第一个值,其余行不显示。
检查:我在main中创建了一个ListModel/ListElement。现在ListView工作正常,显示所有值
我怀疑信号发出后,错误发生了。
代码片段:
main.qml
ListView {
id: idListView
anchors {
left: parent.left
leftMargin: 10 * scaleFactor
right: parent.right
rightMargin: 10 * scaleFactor
top: rectangleToolBar.bottom
topMargin: 10 * scaleFactor
bottom: rectangleStatusBar.top
bottomMargin: 10 * scaleFactor
}
// model: objHomeController.detailsModel // Display only one row
//model: idListmodel //Working fine
delegate: comsearchDelegate
spacing: 10 * scaleFactor
clip: true
highlight: Rectangle {
color: 'grey'
Text {
anchors.centerIn: parent
color: 'white'
}
}
focus: true
}
Component {
id: comsearchDelegate
Row {
spacing: 10 * scaleFactor
Column {
Layout.alignment: Qt.AlignTop
Text { text: title; font { pixelSize: 14 * scaleFactor; bold: true } }
Text { text: description; font { pixelSize: 14 * scaleFactor; bold: true } }
}
}
}
ListModel {
id: idListModel
ListElement{
title : "sdfsdf";
description:"sdfsdfs";
}
ListElement {
title : "sdfsdf";
description:"sdfsdfs";
}
ListElement {
title : "sdfsdf";
description:"sdfsdfs";
}
ListElement {
title : "sdfsdf";
description:"sdfsdfs";
}
}
HomeController.h
Q_PROPERTY(Model* detailsModel READ get_detailsModel WRITE set_detailsModel NOTIFY detailsModelChanged )
HomeController.cpp
void HomeController::set_detailsModel(Model* value)
{
m_detailsModel = value;
//value has correct values - checked.
emit detailsModelChanged(value);
}
Model* HomeController::get_detailsModel(void)
{
return m_detailsModel;
}
void HomeController::getAllData()
{
m_detailsModel->clear();
m_detailsModel->updateModel(eveReadXML());
set_detailsModel(m_detailsModel);
}
Model.cpp
void Model::updateModel(const QList<Details> & details)
{
if(this->rowCount() > 0) {
this->clear();
}
beginInsertRows(QModelIndex(),rowCount(),rowCount());
m_modelData.append(details);
endInsertRows();
}
因为我来自。net背景,我想了解绑定Listview/GridView到一个数据表或XML。在这里,我遵循,创建类名为Details [Details.h]和创建Model.h/Model.cpp和获取值从那里和绑定到ListView。我做得对吗,还是我们有其他流程。任何教程/代码片段/项目链接,高度赞赏
要从c++中定义ListModel,您需要子类化QAbstractListModel
https://doc.qt.io/qt-5/qabstractlistmodel.html您可以在这个项目中以QQmlObjectListModel为例:http://gitlab.unique-conception.org/qt-qml-tricks/qt-qml-models
或者克隆它并在你的项目中使用,如下所示:
Q_PROPERTY(QQmlObjectListModel<Details>* detailsModel READ get_detailsModel WRITE set_detailsModel NOTIFY detailsModelChanged)
相关文章:
- 如何告诉 gcc 显示您使用的优化标志列表
- 动态填充的组合框不显示文本,列表未定义
- 程序输入名称和高度并显示它。我不知道如何显示列表中最高人的姓名和身高
- 尝试从列表中随机选取单个元素并将其显示为C++
- C/C++intellisense 0.26.1不显示结构成员列表
- 如何在屏幕上显示对象列表?
- 如何重载运算符<<显示我的列表
- 如何显示目录中的文件列表
- 如何在函数运行时逐个显示列表项
- 当鼠标悬停在 MFC C++ 中列表控件的列标题上时,可视显示工具提示
- 在 MFC C++中悬停列表控件的列标题的可视化显示工具提示
- 使用 Struct 进行 mp3 播放器模拟C++(不需要播放 mp3 的唯一显示列表)
- 列表视图最初不显示数据
- 显示链接列表内联
- 如何显示图形邻接列表的元素?
- 使用C /Winrt,带有设备的填充列表框,显示其名称
- 我写了此方法来删除链接列表的重复元素,但它显示了分段故障,原因
- 数组初始值设定项必须是初始值设定项列表错误未显示
- C 链接列表显示全部
- 析构函数问题 + 列表显示