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. What is the maximum length of string that QString object can hold?
Forum Update on Monday, May 27th 2025

What is the maximum length of string that QString object can hold?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 22.3k Views
  • 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.
  • P Offline
    P Offline
    pratik041
    wrote on 11 Oct 2011, 10:54 last edited by
    #1

    I mean how many characters we can assign at once to Qstring object?

    Pratik Agrawal

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on 11 Oct 2011, 10:59 last edited by
      #2

      @QString::size ()@ return int value, so I think, length limit is maximum integer value.

      UPD: Of course, if you have enough memory

      --
      Vasiliy

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on 11 Oct 2011, 11:04 last edited by
        #3

        As far as I remember it is 2^30.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pratik041
          wrote on 11 Oct 2011, 11:05 last edited by
          #4

          Ya I was also thinking like that. Thank's ...........

          Pratik Agrawal

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vsorokin
            wrote on 11 Oct 2011, 11:09 last edited by
            #5

            @Lucas, not guarantied for 64 bit arc

            --
            Vasiliy

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on 11 Oct 2011, 11:28 last edited by
              #6

              I have to admit that this piece of information dates back where 64 bit didn't really matter. However, you shouldn't rely on that you can store more than 2^30 in a QString, because usually you can't - even on 64 bit architectures.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on 11 Oct 2011, 13:04 last edited by
                #7

                2^30 is 1073741824 characters, but QString being UTF16, that means a memory usage of 2.147.483.648 bytes, plus some additional bytes around that. For a single piece of data in your application. That's 2 GB worth of data, if I'm not mistaken. Not the best idea to keep that in a single block of memory, and then I am not even talking yet of temporaries that might also be in memory at the same time (like a byte array of the same size from a file you just read, for instance).

                To summarize: if you find yourself wondering about reaching this limit, you had better start wondering about your design at a more fundamental level.

                1 Reply Last reply
                0

                1/7

                11 Oct 2011, 10:54

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved