Search code examples
c++stringqtqt4xerces-c

Convert QString to a Xerces string


I want to convert a QString to an XMLCh const * to be used by Xerces-C++.

The former can be "transformed" to a NUL-terminated const ushort * in host byte-order in (I think) O(1) time. The latter is also a UTF-16 string, but I'm not sure in which byte-order.

Has anyone tackled this problem before? I don't feel like doing lots of string copying.


Solution

  • Perhaps:

    const XMLCh* QtoX(const QString& s) { return (s.utf16()); }
    QString XtoQ(const XMLCh* x) { return QString::fromUtf16(x); }
    

    from here? I have no personal experience with this.