PDA

View Full Version : QFile::OpenError on when file has write protection and on when opened



Raghaw
11th October 2010, 09:13
Hi,
Is there any way by which we can differentiate on when QFile::FileError returns QFile::OpenError.When the particular file is has write protection then also the file is returning this code and when the file is opened then also its returning QFile::OpenError ?

Actually i have to check for write protection of file .Here is my code for your help

QFile telegramFile(filePath);
QFileInfo fileInfo(telegramFile);
QTextStream telegramStream(&telegramFile);

if(!fileInfo.isWritable())
{
QMessageBox *mBox = new QMessageBox();
mBox->setText(QObject::tr("m_This File is write-protected.Do you want to overwrite it?"));
mBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
mBox->setIcon(QMessageBox::Warning);
mBox->setWindowTitle(QObject::tr("m_Warning"));

switch(mBox->exec())
{
case QMessageBox::Yes:
chk = telegramFile.setPermissions(QFile::WriteUser);
break;

case QMessageBox::No:
return false;

default:
return false;
}
}

if(!telegramFile.open(QIODevice::WriteOnly))
{
QMessageBox *mBox = new QMessageBox();
int errorVal = telegramFile.error();
mBox->setText(telegramFile.errorString());
mBox->exec();
telegramFile.close();
return false;
}
if(telegramFile.isOpen())
telegramStream << m_dataBuffer.toUtf8();


Any help would be greatly appreciated.Thanks

Ginsengelf
11th October 2010, 10:21
Hi, you can use QFileInfo::isWritable () to check if a file is writable by the user.

Ginsengelf

edit: did not read you full post...