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. Edit a QString
Forum Updated to NodeBB v4.3 + New Features

Edit a QString

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 586 Views 4 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.
  • Q Offline
    Q Offline
    QtFranchise
    wrote on last edited by
    #1

    Hi, I have a QString str, as function parameter I need to edit it inside the function, say

    void edit(QString str)
    {
    //Edit str here
    // like str[i] = str[i] + 10;
    // Changes should be saved in str and to be reflected in called function
    }

    I know how to do this with char*
    char str[] = "Hello";

    for (int i = 0; i < strlen(str); i++)
    str[i] = str[i] + 10;

    How to do the same with QString

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      Learn the C++ language before attempting to use Qt. Most of the framework won't make sense to you unless you understand the basics.

      I light my way forward with the fires of all the bridges I've burned behind me.

      1 Reply Last reply
      7
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi

        This is not really a Qt issue but more the difference between
        using char * and string class type.
        Anyway, You are giving it a copy. so anything you do in
        the function will not reflect in the original.

        void edit(QString str) << sends a copy
        {
        }
        
        void edit(QString  &str) << sends a refernce so we modify the orginal
        {
        }
        
        
        1 Reply Last reply
        7
        • Q Offline
          Q Offline
          QtFranchise
          wrote on last edited by
          #4

          :) Ok got it

          Pablo J. RoginaP 1 Reply Last reply
          0
          • Q QtFranchise

            :) Ok got it

            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

            @QtFranchise so is your issue solved? please don't forget to mark your post as such!

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            2

            • Login

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