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. How can i prepend the string in the list of string?
QtWS25 Last Chance

How can i prepend the string in the list of string?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.8k 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 last edited by
    #1

    I have a list QList<QString>list;
    Initially i have inserted some string in the list, afterwards i want to prepend some data in the each string in the list. I have tried the following code but getting error
    @
    for (int count = 0; count < list.size (); count ++) {
    list.at (count).prepend (temp_string);
    }
    @

    How can i achieve it?

    Pratik Agrawal

    1 Reply Last reply
    0
    • D Offline
      D Offline
      derf_r
      wrote on last edited by
      #2

      maybe

      (list.at (count)).prepend (temp_string);

      Frederic

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KA51O
        wrote on last edited by
        #3

        .at(int i) returns a const reference, you need to use the [] operator if you want to change the returned reference.
        @
        for (int count = 0; count < list.size (); count ++) {
        list[count].prepend (temp_string);
        }
        @

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pratik041
          wrote on last edited by
          #4

          [quote author="KA51O" date="1331644359"].at(index) returns a const reference you need to use the [index] operator if you want to change the returned data.
          @
          for (int count = 0; count < list.size (); count ++) {
          list[count].prepend (temp_string);
          }
          @[/quote]

          Thanks now it is working.

          Pratik Agrawal

          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