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. Including a text file in qml
Forum Updated to NodeBB v4.3 + New Features

Including a text file in qml

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 2.9k 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.
  • M Offline
    M Offline
    mela
    wrote on last edited by
    #1

    hi, i wanted to include a text file in my qml file. the text file includes a number of jokes that i am going to display when a button is clicked. so, it means i am using a text file as a storage/database. how do i do that? please help

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2
      • QML Store your jokes in a ListModel or an JavaScript array.
      • QML/C++ Store your jokes in a ListModel or an JavaScript array or distribute it along with your application (either as file or as a resource), parse it (using C++ code) to a QStringList and expose this list using a context property.
      1 Reply Last reply
      0
      • M Offline
        M Offline
        mela
        wrote on last edited by
        #3

        If I have 150 jokes, that means I have to store all of them in a ListModel right? This is the scenario: user clicks on button, button loads file with jokes and goes to next page. How can I include it in another qml file?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          I would store the content externally from the qml to display it in. Perhaps you can store the jokes in a simple XML format, that you can then read using a model?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mela
            wrote on last edited by
            #5

            okay. i based my actions on your answer.

            i stored my contents inside a text file (our professor's requiring us to do so)

            i made this code

            @import QtQuick 1.0
            import com.nokia.symbian 1.0

            Page {
            id: lolPage
            objectName: "lolPage"

                ListModel {
                    id: jokeModel
                    ListElement{
                        joke: Qt.resolvedUrl(jokes.text = TextFile.readLine())
                    }
                Component{
                    id: jokeDelegate
                    ListItem{
                        height: 200
                            Column{
                               Text{
                                    id: textJoke
                                    text: joke
                                    color: "black"
                                    font.pixelSize: 20
                                    }
                                }
            
                            }
                        }
            ListView{
                anchors.fill: parent
                model: jokeModel
                delegate: jokeDelegate
                }
            }@
            

            what am i doing wrong here? i do not know how to call and display the contents of an external file using ListModel.

            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