Signal emit Issue - Listview is not showing full list
Hi,
I am binding an ListView with values passing from the cpp, Pls refer the code.
Issue: Listview displays only one row, mean first value, The rest of the rows are not appeared.
Checked:
I created an ListModel/ListElement in main.qml as test and bind with ListView, Now the Listview just working fine, display all values
I suspect after the signal emit, the error occurs.
Code snippet:
main.qml
----------
Code:
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
--------------------
Code:
Q_PROPERTY(Model* detailsModel READ get_detailsModel WRITE set_detailsModel NOTIFY detailsModelChanged )
HomeController.cpp
--------------------
Code:
void HomeController::set_detailsModel(Model* value)
{
m_detailsModel = value;
//value has correct values - checked.
emit detailsModelChanged(value);
}
Thanks in advacne
Re: Signal emit Issue - Listview is not showing full list
You seem to have forgotten to paste the actually important part of the code, the declaration and implementation of Model.
Your "Checked" section also suspicously is missing any mention of tests you performed on said model.
And please use [code] and [/code] when pasting code.
Cheers,
_
3 Attachment(s)
Re: Signal emit Issue - Listview is not showing full list
Hi,
I had attached the model/class called detail.h
Home Controller.CPP
Code:
void HomeController::getAllData()
{
m_detailsModel->clear();
m_detailsModel->updateModel(eveReadXML()); //Values are Read from an XML file.
set_detailsModel(m_detailsModel);
}
Model* HomeController::get_detailsModel(void)
{
return m_detailsModel;
}
void HomeController::set_detailsModel(Model* value)
{
m_detailsModel = value;
emit detailsModelChanged(value);
}
model.cpp
Code:
void Model::addDetails(const Details &detailslist)
{
m_modelData.append(detailslist);
endInsertRows();
}
I had attached the whole classes model.cpp/model.h/details.h
Query: Am I doing the right approach? Since I am new to this.
Attachment 12177Attachment 12178Attachment 12179
Re: Signal emit Issue - Listview is not showing full list
Hmm.
removeRows() is obviously wrong as it only ever removes one item, but that should have an impact on the initial listing.
clear() and updateDetails() could just use beginResetModel() and endResetModel() as they are changing the whole model.
Have you verified the model's implementation, e.g. with unit test?
You could also add a case for Qt::DisplayRole in data() and use the model with a widget QListView to rule out any QML/C++ interaction problems.
Cheers,
_