How does QByteArray gets assigned to QStriing
-
In the following code
QFile data(ofilename.toLatin1().constData());
QString line;
if (data.open(QFile::ReadOnly)) {
setText(data.readAll());
setModified(FALSE);
data.close();
d_filename = ofilename;
emit fileNameChanged(ofilename);
}data.readAll has return type QByteArray but setText takes QString as argument then how does setText(data.readAll()); conversion happens from QByteArray to QString
-
@Qt-Enthusiast
TheQByteArray
object doesn't get assigned toQString
. Rather a temporaryQString
instance is created from the byte array due to the implicitQString
constructor that accepts a byte array and thanks of course to the overloading rules in C++.PS:
QFile data(ofilename.toLatin1().constData());
should just be:
QFile data(ofilename);
As per the respective
QFile
constructor.