PDA

View Full Version : QDir and QFile



sabeesh
27th September 2007, 13:19
Hi,
I am using QT.4.3 and in my program I give a code like this for open a file as readonly mode.
QDir m_ConfigDir;
QFile m_ConfigFile;

m_ConfigDir.setPath(QDir::homePath() + "/.CCTEST");
m_ConfigFile.setFileName(m_ConfigDir.path() + "/config.xml");

if (!m_ConfigFile.open(QIODevice::ReadOnly)){
qDebug()<<"Failed to open configuration file"<<m_ConfigFile.fileName();
}

and when I run the program, it display the message like, "Failed to open configuration file".
Why?

How can I solve this probs?
Please help me...

rajesh
27th September 2007, 13:43
sabeesh,

Before opening the file please check
QString fileName = m_ConfigFile.fileName();
and check fileName contains correct path, then check that file is exist on that location.
or
you can check
if(m_ConfigFile.exists ())
{
if (!m_ConfigFile.open(QIODevice::ReadOnly)){
qDebug()<<"Failed to open configuration file"<<m_ConfigFile.fileName();
}
}