Results 1 to 2 of 2

Thread: QDir and QFile

  1. #1
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDir and QFile

    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...

  2. #2
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QDir and QFile

    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();
    }
    }

  3. The following user says thank you to rajesh for this useful post:

    sabeesh (28th September 2007)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.