Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Enum with QList and Pointers
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Enum with QList and Pointers

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 4.6k 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.
  • E Offline
    E Offline
    Elegant
    wrote on last edited by
    #1

    Hi, I'm currently trying to convert my QList<QString*> to an enum version so it can be faster.

    I would like to do the following, QList<EnumType*>. I am wondering if there is any reason I shouldn't do this. I could really benefit from the pointer in the QList for my next step which is to convert it to a QQmlListProperty<EnumType> which takes a QList<EnumType*>.

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      How do you plan to use your list? I'd use strings instead of enums if I want to generate the type names dynamically. Otherwise, I don't see why you shouldn't change to enums.

      However, you should generally store both enums and QStrings as plain values instead of pointers, for the same reason you'd store integer values instead of integer pointers. QStrings are "implicitly shared":http://qt-project.org/doc/qt-5.1/qtcore/implicit-sharing.html, so copying them is a very efficient process (unlike strcpy() or strdup()).

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Elegant
        wrote on last edited by
        #3

        QQmlListProperty has a constructor for a list of pointers, I supposed I can just create the functions required for it to work when it's not a list of pointers and just a list of "primitives" but was hoping to avoid the hassle.

        The purpose is to get access to the QList within QML. I also want it to be an enum as it will be used in an AI algorithm that will copy data quite often as well as comparing it. Unless QString comparisons can be done just as quickly I would prefer to save as much time as I can during computation.

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          You'll need to find a different approach, unfortunately. QQmlProperty does not work on strings or enums. From the "QQmlListProperty documentation":http://qt-project.org/doc/qt-5.1/qtqml/qqmllistproperty.html:
          "QQmlListProperty can only be used for lists of QObject-derived object pointers."

          What do you with to do with your list in QML?

          Integer comparisons are always faster than string comparisons (well, the two might be equal if your strings all start with different characters).

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Elegant
            wrote on last edited by
            #5

            Changing around how I've set up my code for this to make it easier. Marking as solved in the mean time.

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              I saw your other thread: http://qt-project.org/forums/viewthread/33968/ Yes, having a Pet class that contains all the pet attributes that is the usual way to do it in OOP.

              All the best with your project.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              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