Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to separate a program in Model/View/Controller
Qt 6.11 is out! See what's new in the release blog

How to separate a program in Model/View/Controller

Scheduled Pinned Locked Moved QML and Qt Quick
12 Posts 4 Posters 7.0k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #3

    exactly, I want to separate it in 3 QML files

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #4

      You can put XmlListModel in separate file (let's call it MyModel.qml) and use MyModel from your qml code (if it will be in another directory you should import this path). Please read Qt Assistant to get further information

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #5

        That you can always do that.. have three qml files and have your list view, delegate, and model in those files. But you need to connect them all the above qml file. I mean creating concrete objects of those three items and assigning your model element to Model and same for delegate.

        But I don't see a good reason to separate them? do you have any reason.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #6

          "This":http://doc.qt.nokia.com/4.7/qdeclarativemodules.html#qml-modules might help you

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #7

            The purpose of separating them is to have a QML file that contains the data model (XMLlistModel), another that includes the views (TextInput, ListView), and the third to start the program

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #8

              the problem is ListView can not find the id of XMLlistModel if I separated the two into two files

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DenisKormalev
                wrote on last edited by
                #9

                You should not use them by id, but create new objects from your qml files.

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #10

                  Read this "Managing Documents":http://doc.qt.nokia.com/4.7/qdeclarativedocuments.html

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #11

                    You don't give up :)
                    First read http://doc.qt.nokia.com/4.7/qdeclarativedocuments.html

                    then to solve your problem....

                    XmlModel.qml
                    @ import QtQuick 1.0
                    XmlListModel {
                    id: forecastModel
                    source: "http://www.google.com/ig/api?weather=&hl=fr"
                    query: "/xml_api_reply/weather/forecast_information"
                    XmlRole { name: "city"; query: "city/@data/string()" }
                    }
                    @

                    TextDeligate.qml
                    @ import QtQuick 1.0

                    Component {
                    Text {
                    id : textItem
                    font.family: "Univers LT Std";
                    color: "#c8c8c8";
                    width: parent.width;
                    font.pixelSize: 30
                    text: city
                    anchors.centerIn: parent.centerIn
                    }
                    }
                    @

                    ListItem.qml
                    @ import QtQuick 1.0
                    ListView {
                    x: 145; y: 325; width: 594; height: 48;
                    }
                    @

                    now in your main.qml

                    @ import QtQuick 1.0

                    Item {
                           XmlModel {
                                    id: modelItem
                           } 
                           ListItem {
                              id: listItem
                              model: modelItem
                              deligate: TextDeligate { }
                     }
                    

                    }@

                    There could be syntax errors, please correct them. Understand what I tried to do. Don't just copy :)

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #12

                      tank you Vijay Bhaska Reddy i try to do it

                      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
                      • Unsolved