Important: Please read the Qt Code of Conduct -

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

  • 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 =;
    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.

  • Thanks for the pointer.
    Is this what you meant?

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

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

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

Log in to reply