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. [SOLVED]Pointer to the first character of a QString?
QtWS25 Last Chance

[SOLVED]Pointer to the first character of a QString?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k 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.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by
    #1

    Hi everyone,

    Does anyone know how can I get a pointer to the first character of a given string?

    I have a small function similar to

    @static QString firstChar(const QString s)
    {
    c = s.at(0);
    return c;
    }@

    that will return the first character of a string, yet I decided it would be better if I just got a pointer to the first character of my original string.

    Thank you for your time.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      How about this "one.":http://doc.qt.io/qt-5/qstring.html#constData

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • ealioneE Offline
        ealioneE Offline
        ealione
        wrote on last edited by
        #3

        Thanks for the pointer.
        Is this what you meant?

        @const QChar* firstChar(const QString* s)
        {
        const QChar* c = s.constBegin();
        return c;
        }@

        1 Reply Last reply
        0
        • ealioneE Offline
          ealioneE Offline
          ealione
          wrote on last edited by
          #4

          Quick question: I also noticed below that, the function QString::​constData(), but I couldn't find any examples so I am not sure I understood how can I iterate a QString using it.

          EDIT:
          I also understood how to use constData. After a few tests I think I am ok now. Thanks for the link.

          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