Results 1 to 4 of 4

Thread: Signal emit Issue - Listview is not showing full list

  1. #1
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default 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
    ----------
    Qt Code:
    1. ListView {
    2. id: idListView
    3. anchors {
    4. left: parent.left
    5. leftMargin: 10 * scaleFactor
    6. right: parent.right
    7. rightMargin: 10 * scaleFactor
    8. top: rectangleToolBar.bottom
    9. topMargin: 10 * scaleFactor
    10. bottom: rectangleStatusBar.top
    11. bottomMargin: 10 * scaleFactor
    12. }
    13. // model: objHomeController.detailsModel // Display only one row
    14. //model: idListmodel //Working fine
    15. delegate: comsearchDelegate
    16. spacing: 10 * scaleFactor
    17. clip: true
    18.  
    19. highlight: Rectangle {
    20. color: 'grey'
    21. Text {
    22. anchors.centerIn: parent
    23. color: 'white'
    24. }
    25. }
    26. focus: true
    27. }
    28.  
    29.  
    30. Component {
    31.  
    32. id: comsearchDelegate
    33. Row {
    34. spacing: 10 * scaleFactor
    35.  
    36. Column {
    37. Layout.alignment: Qt.AlignTop
    38.  
    39. Text { text: title; font { pixelSize: 14 * scaleFactor; bold: true } }
    40. Text { text: description; font { pixelSize: 14 * scaleFactor; bold: true } }
    41.  
    42. }
    43. }
    44. }
    45.  
    46. ListModel
    47. {
    48.  
    49. id: idListModel
    50. ListElement{
    51. title : "sdfsdf";
    52. description:"sdfsdfs";
    53.  
    54. }
    55. ListElement{
    56. title : "sdfsdf";
    57. description:"sdfsdfs";
    58.  
    59. }
    60. ListElement{
    61. title : "sdfsdf";
    62. description:"sdfsdfs";
    63.  
    64. }
    65. ListElement{
    66. title : "sdfsdf";
    67. description:"sdfsdfs";
    68.  
    69. }
    70. }
    To copy to clipboard, switch view to plain text mode 
    HomeController.h
    --------------------
    Qt Code:
    1. Q_PROPERTY(Model* detailsModel READ get_detailsModel WRITE set_detailsModel NOTIFY detailsModelChanged )
    To copy to clipboard, switch view to plain text mode 
    HomeController.cpp
    --------------------
    Qt Code:
    1. void HomeController::set_detailsModel(Model* value)
    2. {
    3. m_detailsModel = value;
    4.  
    5. //value has correct values - checked.
    6. emit detailsModelChanged(value);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Thanks in advacne
    Last edited by anda_skoa; 14th October 2016 at 18:24. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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. #3
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Signal emit Issue - Listview is not showing full list

    Hi,

    I had attached the model/class called detail.h

    Home Controller.CPP
    Qt Code:
    1. void HomeController::getAllData()
    2. {
    3.  
    4. m_detailsModel->clear();
    5. m_detailsModel->updateModel(eveReadXML()); //Values are Read from an XML file.
    6. set_detailsModel(m_detailsModel);
    7. }
    8.  
    9. Model* HomeController::get_detailsModel(void)
    10. {
    11. return m_detailsModel;
    12. }
    13.  
    14.  
    15. void HomeController::set_detailsModel(Model* value)
    16. {
    17. m_detailsModel = value;
    18. emit detailsModelChanged(value);
    19. }
    To copy to clipboard, switch view to plain text mode 

    model.cpp

    Qt Code:
    1. void Model::addDetails(const Details &detailslist)
    2. {
    3. beginInsertRows(QModelIndex(),rowCount(),rowCount());
    4. m_modelData.append(detailslist);
    5. endInsertRows();
    6. }
    To copy to clipboard, switch view to plain text mode 

    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.

    model.cppdetails.hmodel.h

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

Similar Threads

  1. issue with loading QML ListView through C++
    By ejoshva in forum Newbie
    Replies: 1
    Last Post: 17th July 2015, 10:57
  2. listview issue
    By joko in forum Qt Quick
    Replies: 0
    Last Post: 13th July 2015, 19:17
  3. Replies: 6
    Last Post: 26th August 2014, 23:50
  4. Issue with List of objects made of QObject
    By alizadeh91 in forum Qt Programming
    Replies: 4
    Last Post: 3rd June 2013, 21:38
  5. Day showing wrongly in thread list in NewBie
    By karthic in forum General Discussion
    Replies: 1
    Last Post: 29th April 2012, 15:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.