×

Discussion Board

Results 1 to 10 of 10

Thread: QFile problem

  1. #1
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    130

    QFile problem

    Hi,

    I am using Qt4.6.2.

    I tried using QFile to open the file. Problem is even the text file is not opening.

    Here is my code:
    Code:
    QString fileName = ":/resource/textFile.txt";
    		
    if (!fileName.isEmpty()) {
        QFile file(fileName);
    	
        if (!file.open(QIODevice::ReadOnly)) {
        QMessageBox::information(this, tr("Unable to open file"),
    					file.errorString());
        return;
        }
    		
        QDataStream in(&file);
        QString str;
        in << str;
        QMessageBox::information(this, "test", str);
    }
    It is always going into the error state and printing "unknown error" as it is not opening. Did I miss anything in that. The file is in the path.

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    12

    Re: QFile problem

    Hai,

    Try like this

    QFile oReadFile = 0;

    strFRPth = ":/resource/sample.txt";
    oReadFile.setFileName(strFRPth);
    bool bResult = oReadFile.open(QIODevice::ReadOnly );

    if(oReadFile.isOpen() && bResult != 0)
    {
    QDataStream in(&file);
    QString str;
    in << str;
    QMessageBox::information(this, "test", str);
    }
    else
    {
    QMessageBox::information(this, tr("Unable to open file"),
    file.errorString());
    return;

    }

    you can make simple then this.

  3. #3
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    130

    Re: QFile problem

    Quote Originally Posted by devi.ch View Post
    QFile oReadFile = 0;
    I am getting error in this statement. What is this all about..

    illegal access from 'QFile' to protected/private member 'QFile::QFile(const QFile &)'

  4. #4
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    130

    Re: QFile problem

    I am getting the bResult value false. It is not opening and going to error message "unknown error"

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    12

    Re: QFile problem

    if bResult is false that means your input path is in correct

    specify your input path correctly

    for example :
    strpth = "E:/resource/sample.txt" what ever the driver C or D or E specify that

    or try this

    strpth ="../resources/sample.txt"

    I am sure it will work

  6. #6
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    130

    Re: QFile problem

    Quote Originally Posted by devi.ch View Post
    "E:/resource/sample.txt"
    It's working when I give the entire path
    and getting false when i use like below,

    strpth ="../resources/sample.txt"
    or
    strpth =":/resources/sample.txt"
    path is correct and I checked.

    Now I want to use the same in symbian. Using carbide to do this. I cant give the entire path for symbian development. Kindly help me.

    Also is it possible to extract the zip file into directory using Qt? If so, please tell me how to do.

    Regards,
    Bala

  7. #7
    Registered User
    Join Date
    Feb 2010
    Posts
    12

    Re: QFile problem

    As per my knowledge there is no such methods in QT to extract zip files into a directory. But in net you can find zipper class which help you to unzip a zip file and store the files in folder which are developed in C++. By using methods in that you can able to do this.

  8. #8
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: QFile problem

    Note, that
    Code:
    QString fileName = ":/resource/textFile.txt";
    is a name of resource file.
    More details: http://qt.nokia.com/doc/4.6/resource...he-application

  9. #9
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: QFile problem

    In my experience, when you have trouble opening a member of a resource file, it's usually because

    1) The member isn't actually in the resource file, or

    2) The resource file isn't being loaded by your application.

    First, make sure that the file referenced by the resource file is findable (at the specified location) during the build. Try "touching" the resource file and rebuilding your application. (You can verify that the file is getting included in the resource file by scanning the qrc_XXX.cpp file for the name of your file.)

    If that doesn't work, try adding a "Q_INIT_RESOURCE(MyResourceFile);" statement to your main.cpp (after the QApplication).

  10. #10
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    130

    Re: QFile problem

    Hi all,

    Actually the qrc.cpp file was not generated in my project. I gave the *.qrc file manually in my *.pro file and then after building, it is generated. That's why I got error.

    Thanks for your kind help.

    Regards,
    Bala

Similar Threads

  1. STLPort namespace issue
    By yickhong in forum Open C/C++
    Replies: 0
    Last Post: 2009-04-09, 08:54
  2. SyncML link problem
    By samuel_ in forum Symbian
    Replies: 4
    Last Post: 2009-03-27, 08:02
  3. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  4. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  5. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •