How does QByteArray gets assigned to QStriing

  • In the following code

    QFile data(ofilename.toLatin1().constData());
    QString line;
    if ( {
    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 Champions 2016

    The QByteArray object doesn't get assigned to QString. Rather a temporary QString instance is created from the byte array due to the implicit QString constructor that accepts a byte array and thanks of course to the overloading rules in C++.


    QFile data(ofilename.toLatin1().constData());

    should just be:

    QFile data(ofilename);

    As per the respective QFile constructor.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.