Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Not Able to view the List MODEL elements From CPP Until After Reloading the Qml Page.
Forum Updated to NodeBB v4.3 + New Features

Not Able to view the List MODEL elements From CPP Until After Reloading the Qml Page.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 178 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AROH
    wrote on last edited by AROH
    #1

    I have a qml list used to display the list of networks available whose model is been taken from data() in CPP, I have a created a custom class that inheirts QAbstractListModel which is responsible to take the data from Dbus and then return Qlist accordingly.

    In order to access this data in qml I have created a Network plugin  using qmlRegisterSingletonType<>.
     Coming to the main issue , when Toggling the switch to ON I need to display the list of available networks but when I do this the list is not been shown.
    The list only comes up Ones I go back and come to page again i.e. the list is shown only after reloading the QML Page that displays the list.But if a pass an list model which is defined the in the QML page itself then the list elements are visible as expected.

    Can any one suggest me what needs to be done, so that I can see the list elements that available in the model when I Toggle the network button.

    Reference for How I Created the Plugin-

    void NetwrokPlugin::registerTypes(const char *uri)
    {
    //SettingsController is the custom class which has data() defined in it  and NetworkListModel is the plugin name.
        qmlRegisterSingletonType<SettingsController>(uri, 1, 0, "NetworkListModel",
            [](QQmlEngine* engine, QJSEngine*) -> QObject* {
                return new SettingsController(engine);
            });
    }
    

    Code for the List View: -

    ListView{
         id: root
    
        property var networkName: NetworkListModel.name
         model: NetworkListModel
         delegate: delegateComponent
    
         Component{
              id: delegaeteComponent 
              
              Column {
                          Text {
                                   //anchors
                                   //name is a parameter that is coming from CPP model 
                                   text : name!== undefined ? name: ""
                           }
                           Text {
                                    text :NetrworkListModel.connectedName === name ? "connected : " 
                          }
                }
          }
        Connections {
            target: NetworkListModel
            onNetworkNameChanged: {
                networkName = NetworkListModel.Name;
            }
        }
    }
    

    Thanks In Advance!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Code has some issue. I don't this this is working code. Please give us the working code. We will be able to help you.

      Also size for the list view is missing. As such code should work. I tried with minimal example by taking the snippets from your code. It works.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved