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. Beginner questions
Qt 6.12 LTS is out! See what's new in the release blog

Beginner questions

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 457 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.
  • CesarC Offline
    CesarC Offline
    Cesar
    wrote on last edited by
    #1

    Hello guys i wonder if someone could help with some beginner questions:

    Q1)
    When I use .replace and i don't want to replace the original string, do I need to make a copy of it? or is there an API that doesn't replace the original string?

    example:

    QString str = "a - b";
    QString str2 =  str.replace(str, "-"); 
    

    this will replace the content of str but I would like it to don't, do I need to make a copy before?

    Q2)
    I wonder if there's any API to count the number of replacements done on an str.replace?

    I was reading the docs of replace but I didn't see any count parameter https://doc.qt.io/qt-6/qstring.html

    Do I need to build mine or maybe use regex match and count the size of the match object?

    Q3)
    Is possible to check the substring without declaring a string before?

    QString s = "...";
    QString s2 = "100000";
    s += s2.mid(0, 6 - (s.length() % 6));
    

    to something like

    QString s "...";
    s += "100000".mid(0, 6 - (s.length() % 6));
    

    Q4)
    Is it possible to see the content of QRegularExpressionMatch match object in the debugger watch of Visual Studio? it only shows some pointers.

    Christian EhrlicherC 1 Reply Last reply
    0
    • CesarC Cesar

      Hello guys i wonder if someone could help with some beginner questions:

      Q1)
      When I use .replace and i don't want to replace the original string, do I need to make a copy of it? or is there an API that doesn't replace the original string?

      example:

      QString str = "a - b";
      QString str2 =  str.replace(str, "-"); 
      

      this will replace the content of str but I would like it to don't, do I need to make a copy before?

      Q2)
      I wonder if there's any API to count the number of replacements done on an str.replace?

      I was reading the docs of replace but I didn't see any count parameter https://doc.qt.io/qt-6/qstring.html

      Do I need to build mine or maybe use regex match and count the size of the match object?

      Q3)
      Is possible to check the substring without declaring a string before?

      QString s = "...";
      QString s2 = "100000";
      s += s2.mid(0, 6 - (s.length() % 6));
      

      to something like

      QString s "...";
      s += "100000".mid(0, 6 - (s.length() % 6));
      

      Q4)
      Is it possible to see the content of QRegularExpressionMatch match object in the debugger watch of Visual Studio? it only shows some pointers.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Cesar said in Beginner questions:

      do I need to make a copy before?

      Yes, as stated in the documentation it's modifying the object.

      Do I need to build mine

      Yes you have to do it on your own.

      s += "100000".mid(0, 6 - (s.length() % 6));

      Apart from a missing usecase - use QLatin1String("100000") or QStringLiteral("100000")

      Is it possible to see the content of QRegularExpressionMatch match object in the debugger watch

      Yes, it should - see https://wiki.qt.io/IDE_Debug_Helpers

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3

      • Login

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