Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can i prepend the string in the list of string?
Qt 6.12 LTS is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.4k 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.
  • ? Offline
    ? Offline
    A Former User
    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?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      maybe

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

      Frederic

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        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
        • ? Offline
          ? Offline
          A Former User
          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.

          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
          • Unsolved