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. Immutable QList
Forum Updated to NodeBB v4.3 + New Features

Immutable QList

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.3k 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.
  • D Offline
    D Offline
    diredko
    wrote on last edited by
    #1

    Hello everyone,
    I wonder if there is a way to get immutable list from regular QList. A fail-safe list is better but I would appreciate any suggestions.
    Thanks in advance)

    kshegunovK 1 Reply Last reply
    0
    • D diredko

      Hello everyone,
      I wonder if there is a way to get immutable list from regular QList. A fail-safe list is better but I would appreciate any suggestions.
      Thanks in advance)

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @diredko
      Hello.

      I wonder if there is a way to get immutable list from regular QList.

      Is that what you're after?

      QList<int> mutableList;
      const QList<int> & immutableList = mutableList;
      

      A fail-safe list is better

      What do you mean by fail-safe list?

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        diredko
        wrote on last edited by
        #3

        Thanks for your reply)
        I'd like to provide some clarifications:
        By saying "immutable" I meant that after some elements are added to this list, its content cannot be modified - add, remove and insert operations are prohibited or just won't take any effect.
        By saying "fails-safe" I meant that whenever such an operation is called on immutable list no application failure will arise and no exception will be thrown.

        kshegunovK 1 Reply Last reply
        0
        • D diredko

          Thanks for your reply)
          I'd like to provide some clarifications:
          By saying "immutable" I meant that after some elements are added to this list, its content cannot be modified - add, remove and insert operations are prohibited or just won't take any effect.
          By saying "fails-safe" I meant that whenever such an operation is called on immutable list no application failure will arise and no exception will be thrown.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @diredko
          Hello,
          Both your requirements are met by the const keyword in C++. A const object can't be modified and prevents you from calling non-const functions. What is it that you're trying to achieve?

          Kind regards.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • D Offline
            D Offline
            diredko
            wrote on last edited by
            #5

            Thanks for your reply) This is exactly what I needed)

            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