Listview不使用C++/Qml打印模型

Listview不使用C++/Qml打印模型,listview,qml,qt5,qtquick2,Listview,Qml,Qt5,Qtquick2,我目前正尝试基于C++ QStRigListQLIST创建一个ListVIEW。 这里的问题是,列表没有显示,既没有预先填写的列表,也没有更新的列表。使用tableView进行相同的追加 下面是一些代码: NetworkHander.h class NetworkHandler : public INetworkHandler { Q_OBJECT Q_PROPERTY(QList<QString> list READ listApplicati

我目前正尝试基于C++ QStRigListQLIST创建一个ListVIEW。 这里的问题是,列表没有显示,既没有预先填写的列表,也没有更新的列表。使用tableView进行相同的追加

下面是一些代码:

NetworkHander.h

class NetworkHandler : public INetworkHandler
{

  Q_OBJECT

  Q_PROPERTY(QList<QString> list
             READ listApplications
             WRITE setListApplications
             NOTIFY listApplicationsChanged)

  public:
      NetworkHandler();
      ~NetworkHandler();
      Q_INVOKABLE QList<QString> listApplications() const;
      void setListApplications(const QList<QString> &list);

  signals:
      void listApplicationsChanged();

  public slots:
      void replyFinished(QNetworkReply* reply);
      void refresh();
      void open(const QString &file);
      Q_INVOKABLE void getApplications();

  private:
      QList<QString> m_listApplications;
};
启动listview的按钮

ToolButton {
    id: open
    objectName: "open"
    height: menuBar.height
    width: height
    anchors.right: refresh.left
    Image {
        height: parent.height
        width: height
        source: "qrc:/ic_open"
        smooth: true
    }
    onClicked: {
        Qt.createComponent("dialog.qml").createObject(root, {});
        handler.getApplications();
    }
}
import QtQuick 2.0
import QtQuick.Controls 1.1

Item {
  id: dialogComponent
  anchors.fill: parent
  width: screen.width
  height: screen.height

  // Add a simple animation to fade in the popup
  // let the opacity go from 0 to 1 in 400ms
  PropertyAnimation {
      target: dialogComponent;
      property: "opacity";
      duration: 400;
      from: 0; to: 1;
      easing.type: Easing.InOutQuad ;
      running: true
  }

  // This rectange is the a overlay to partially show the parent through it
  // and clicking outside of the 'dialog' popup will do 'nothing'
  Rectangle {
      anchors.fill: parent
      id: overlay
      color: "#000000"
      opacity: 0.6
      // add a mouse area so that clicks outside
      // the dialog window will not do anything
      MouseArea {
          anchors.fill: parent
      }
  }

  ListView {
      id: listview
      width: dialogComponent.width*0.8
      height: dialogComponent.height*0.8
      anchors.centerIn: parent

      Component {
           id: rowDelegate
           Rectangle {
               id: wrapper
               width: listview.width
               height: 100
               Text {
                   anchors.left: parent.left
                   anchors.leftMargin: 20
                   anchors.verticalCenter: parent.verticalCenter
                   font.pixelSize: 40
                   // deligate can direclty use ListElement role name
                   text: modelData
               }
           }
       }

      model: handler.list
      delegate: rowDelegate
      MouseArea {
          anchors.fill: parent
          onClicked: {
              console.log(handler.list);
              dialogComponent.destroy()
          }
      }
  }

  /*TableView {
      id: listView
      width: dialogComponent.width*0.8
      height: dialogComponent.height*0.8
      model: handler.list
      alternatingRowColors: true
      anchors.centerIn: parent
      TableViewColumn {
          role: "dataModel"
          title: "Element"
      }
      MouseArea {
          anchors.fill: parent
          onClicked: {
              console.log(handler.list);
              dialogComponent.destroy()
          }
      }
  }*/
}
最后是listview的qml

ToolButton {
    id: open
    objectName: "open"
    height: menuBar.height
    width: height
    anchors.right: refresh.left
    Image {
        height: parent.height
        width: height
        source: "qrc:/ic_open"
        smooth: true
    }
    onClicked: {
        Qt.createComponent("dialog.qml").createObject(root, {});
        handler.getApplications();
    }
}
import QtQuick 2.0
import QtQuick.Controls 1.1

Item {
  id: dialogComponent
  anchors.fill: parent
  width: screen.width
  height: screen.height

  // Add a simple animation to fade in the popup
  // let the opacity go from 0 to 1 in 400ms
  PropertyAnimation {
      target: dialogComponent;
      property: "opacity";
      duration: 400;
      from: 0; to: 1;
      easing.type: Easing.InOutQuad ;
      running: true
  }

  // This rectange is the a overlay to partially show the parent through it
  // and clicking outside of the 'dialog' popup will do 'nothing'
  Rectangle {
      anchors.fill: parent
      id: overlay
      color: "#000000"
      opacity: 0.6
      // add a mouse area so that clicks outside
      // the dialog window will not do anything
      MouseArea {
          anchors.fill: parent
      }
  }

  ListView {
      id: listview
      width: dialogComponent.width*0.8
      height: dialogComponent.height*0.8
      anchors.centerIn: parent

      Component {
           id: rowDelegate
           Rectangle {
               id: wrapper
               width: listview.width
               height: 100
               Text {
                   anchors.left: parent.left
                   anchors.leftMargin: 20
                   anchors.verticalCenter: parent.verticalCenter
                   font.pixelSize: 40
                   // deligate can direclty use ListElement role name
                   text: modelData
               }
           }
       }

      model: handler.list
      delegate: rowDelegate
      MouseArea {
          anchors.fill: parent
          onClicked: {
              console.log(handler.list);
              dialogComponent.destroy()
          }
      }
  }

  /*TableView {
      id: listView
      width: dialogComponent.width*0.8
      height: dialogComponent.height*0.8
      model: handler.list
      alternatingRowColors: true
      anchors.centerIn: parent
      TableViewColumn {
          role: "dataModel"
          title: "Element"
      }
      MouseArea {
          anchors.fill: parent
          onClicked: {
              console.log(handler.list);
              dialogComponent.destroy()
          }
      }
  }*/
}
我错过什么了吗?空名单的副本

注意console.loghandler.list;给我一个好的清单,不是空的清单或其他任何东西

提前谢谢。

显然,QStringList!=QList

我认为QStringList专门用于将任务打印为listview中的显示。用这个替换所有的旧列表解决了这个问题