Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    3
    4
    2522
    Loading More Posts
    • 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
      pratik041 last edited by

      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 Reply Quote 0
      • D
        derf_r last edited by

        maybe

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

        Frederic

        1 Reply Last reply Reply Quote 0
        • K
          KA51O last edited by

          .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 Reply Quote 0
          • P
            pratik041 last edited by

            [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 Reply Quote 0
            • First post
              Last post