Solved Where is the documentation for QByteRef?
-
Hello,
I can't seem to find the documentation for QByteRef.
I searched the documentation https://doc.qt.io/qt-5/search-results.html?q=qbyteref and nothing for QByteRef is shown.I also tried going through another documentation and click on QByteRef but it takes me to 404 Not found page.
-
Hi,
I would say a doc error.
@Bonnie It's part of the public API so it's not internal.
In any case, QByteRef is the equivalent of QStringRef but for QByteArray.
-
Seems there is no such doc.
Think it as a Qt internal class.
But you can find the full definition of the class in qbytearray.h.
Maybe it is too simple to have a doc ;) -
Hi,
I would say a doc error.
@Bonnie It's part of the public API so it's not internal.
In any case, QByteRef is the equivalent of QStringRef but for QByteArray.
-
Still no documentation for QByteRef for Qt 5.15 in 2022?
QByteRef is the return type of the QByteArray's methods back(), front(), and operator[], but the link are dead.
Qt 6.x returns char&.It's not clear if QByteRef is a reference to a single byte, as bach/front/[] suggest, or if it is a reference to a bytes array, like QStringRef, as suggested by @SGaist.
In the second case:
I would like to share a byte array with two distinct read-only objects. What is the best: construct a QByteArray with 'fromRawData()' or using this QByteRef class? -
@VTiTux said in Where is the documentation for QByteRef?:
Still no documentation for QByteRef for Qt 5.15 in 2022?
No, it's removed in Qt6 and I don't think anyone will add a documentation for this for Qt5 anymore but feel free to do so.
/Edit: removed with 063e39df13dd53975d7d6615aa9f7e8429648aed in 2019 for Qt6
-
The QByteRef class has been removed in Qt 6 so don't use it all.
QByteArray is a COW container so you don't need to do premature optimization.
-
Thank you, it is noted, I drop QByteRef.
@SGaist I have oversimplified my problem a bit. In fact, I have a large QByteArray, and I would like several others QByteArrays to reference subparts of this array, without copying the data. I don't think implicit sharing apply in this case.
QStringRef is a great class for that, for 16-bits QStrings (with .midRef(), LefRef(), and so on). QByteArray doesn't have this equivalent class. But 'fromRawData()' is a suitable solution. -
In Qt6 you can use QByteArrayView
-
@Christian-Ehrlicher Great, thank you!