PDA

View Full Version : Signal emit Issue - Listview is not showing full list



Mathan
14th October 2016, 17:42
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
----------


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);
}

Thanks in advacne

anda_skoa
14th October 2016, 18:27
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
and when pasting code.

Cheers,
_

Mathan
15th October 2016, 12:21
Hi,

I had attached the model/class called detail.h

Home Controller.CPP


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



void Model::addDetails(const Details &detailslist)
{
beginInsertRows(QModelIndex(),rowCount(),rowCount( ));
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.

121771217812179

anda_skoa
15th October 2016, 17:53
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,
_