I have define a QByteArray
class
as arr
instance in Qt. normally, private
members of QByteArray
(and another classes
) are not accessible, else use of friend
members in class
.
Attention bellow code :
void Widget::onBtnRun()
{
QByteArray arr;
arr = "this is a test";
arr.d->size = 5; // stop with compile error-> QByteArray::d is private
QMessageBox::information(this, "", arr);
}
the d
member of QByteArray
is private
and cannot access to that!
but i have edited QByteArray
header
file, so adding bellow line in it's class section, then save that again.
public :
friend Class Widget;
And now i can access to the private
members of QByteArray
class
in Widget
class
, without any problem :
void Widget::onBtnRun()
{
QByteArray arr;
arr = "ABCDEFGHIJKLMNOPQRSTUV";
arr.d->size = 5;
QMessageBox::information(this, "", arr);
}
MessageBox
output now is "ABCDE"
.
Is this a lack for classes
? perhaps this cause appear very problem in future.
how can save private
members from thease problems?
Thanks in advance!