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. Small string manipulation utilities in QtQuick: better a QML singleton or a js file?
Forum Updated to NodeBB v4.3 + New Features

Small string manipulation utilities in QtQuick: better a QML singleton or a js file?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 1.5k Views 2 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
    marco_piccolino
    Qt Champions 2017
    wrote on last edited by
    #1

    We often need to include in our apps small string manipulation functions (usually 4-5 lines of code) that are used in several places. Is it better to have them in a QML singleton or in a JS file? And why? Thank you

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      IMO JavaScript modules are simpler to manage. In you case I'd vote for a js file

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        marco_piccolino
        Qt Champions 2017
        wrote on last edited by
        #3

        thanks @mcosta

        1 Reply Last reply
        0
        • M Offline
          M Offline
          marco_piccolino
          Qt Champions 2017
          wrote on last edited by
          #4

          @mcosta On the other hand, I am also considering the following advice:

          http://doc.qt.io/qt-5/qtquick-performance.html#use-singleton-types-instead-of-pragma-library-scripts

          not sure whether it is written with atomic properties in mind or also JS functions

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

            HI,

            In the link is written

            If you are using a pragma library script to store application-wide instance data,

            you was talking about small functions.

            Obviously if you need to store data (like models, or application-wide data) QObject singleton is the best solution

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              marco_piccolino
              Qt Champions 2017
              wrote on last edited by
              #6

              @mcosta wouldn't making the library pragma be advisable in any case, since I am going to call it from several QML files?

              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