opening file returns error 5 in qt

  • 0
    down vote
    I'm trying to open a file for reading using qt and it doesn't open it, it returns an error 5. I don't know why ?

    QFile obj_file(path) ;

    QString errMsg;
    QFileDevice::FileError err = QFileDevice::NoError;
    if (! {
        errMsg = obj_file.errorString();
        err = obj_file.error();
        qDebug() << QString(" err %1").arg(err) ;
    if (!
        qDebug() << QString("cannot open %1").arg(path) ;
        return ;

  • Lifetime Qt Champion


    The most likely is that your file is not a the path you are providing. For example, if your file is located in your sources and you wrote a relative path in your application code then it won't find it because they are not in the same folder. That's because by default Qt Creator uses Shadow Builds (which is a good thing).

Log in to reply

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