Same as prepend(\a ch).
*/
+/*! \fn QByteArray QByteArray::fromStdString(const std::string &str)
+ \since 5.4
+
+ Returns a copy of the \a str string as a QByteArray.
+
+ \sa toStdString(), QString::fromStdString()
+*/
+
+/*!
+ \fn std::string QByteArray::toStdString() const
+ \since 5.4
+
+ Returns a std::string object with the data contained in this
+ QByteArray.
+
+ This operator is mostly useful to pass a QByteArray to a function
+ that accepts a std::string object.
+
+ \sa fromStdString(), QString::toStdString()
+*/
+
/*! \fn QByteArray::QByteArray(const QByteArray &other)
Constructs a copy of \a other.
#include <string.h>
#include <stdarg.h>
+#ifndef QT_NO_STL
+# include <string>
+#endif
+
#ifdef truncate
#error qbytearray.h must be included before any header file that defines truncate
#endif
void push_front(const char *c);
void push_front(const QByteArray &a);
+#ifndef QT_NO_STL
+ static inline QByteArray fromStdString(const std::string &s);
+ inline std::string toStdString() const;
+#endif
+
inline int count() const { return d->size; }
int length() const { return d->size; }
bool isNull() const;
inline QByteArray &QByteArray::setNum(float n, char f, int prec)
{ return setNum(double(n),f,prec); }
+#ifndef QT_NO_STL
+inline std::string QByteArray::toStdString() const
+{ return std::string(constData(), length()); }
+
+inline QByteArray QByteArray::fromStdString(const std::string &s)
+{ return QByteArray(s.data(), int(s.size())); }
+#endif
#if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED)
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QByteArray &);
This constructor is only available if Qt is configured with STL
compatibility enabled.
- \sa fromAscii(), fromLatin1(), fromLocal8Bit(), fromUtf8()
+ \sa fromAscii(), fromLatin1(), fromLocal8Bit(), fromUtf8(), QByteArray::fromStdString()
*/
/*! \fn QString QString::fromStdWString(const std::wstring &str)
This operator is only available if Qt is configured with STL
compatibility enabled.
- \sa toAscii(), toLatin1(), toUtf8(), toLocal8Bit()
+ \sa toAscii(), toLatin1(), toUtf8(), toLocal8Bit(), QByteArray::fromStdString()
*/
/*!
#ifndef QT_NO_STL
inline std::string QString::toStdString() const
-{ const QByteArray asc = toAscii(); return std::string(asc.constData(), asc.length()); }
+{ return toAscii().toStdString(); }
inline QString QString::fromStdString(const std::string &s)
{ return fromAscii(s.data(), int(s.size())); }