Discussion Board

Results 1 to 15 of 15
  1. #1
    Registered User H0LL0's Avatar
    Join Date
    Nov 2010
    Posts
    38
    On a Symbian Device i have the following problem:

    qDebug() << QDir("C:/DATA").exists(); // true
    qDebug() << QDir(QApplication::applicationDirPath()).exists(); // false
    qDebug() << QFile::exists(QApplication::applicationDirPath() + "/version.txt"); // true

    what am i doing wrong? the directory doesnt exist but a file in it does.

    The only Explanation I have is that I'm using Qt 4.6.3 instead of 4.7 is that the problem?

  2. #2
    Nokia Developer Champion kkrish's Avatar
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,029
    what QApplication::applicationDirPath() is returning ?

  3. #3
    Registered User kamalakshan's Avatar
    Join Date
    Jun 2007
    Location
    Mumbai, India
    Posts
    1,998
    Just check if you have to convert from Symbian dir separator format to Qt format.

  4. #4
    Nokia Developer Champion savaj's Avatar
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034
    Yes, it is correct behavior of application. In Qt (for Symbian) this function will return the application private directory, not the path to executable itself. So if you are not creating it at installation time (by pasting some file in it) just create it right before its first use...

    For "qDebug() << QFile::exists(QApplication::applicationDirPath() + "/version.txt"); // true" i guess QApplication::applicationDirPath() returning NULL but you have "/version.txt" somewhere, where the QFile::exists is looking for.

    Provide some more input. like are you testing on device or simulator? and location of your version.txt file.
    Last edited by savaj; 2011-04-19 at 12:20. Reason: Adding more info

  5. #5
    Registered User laa-laa's Avatar
    Join Date
    Aug 2003
    Location
    Oulu, Finland
    Posts
    1,122
    It's because the \private directory itself is not accessible (without AllFilles capability) while \private\youruid is.

  6. #6
    Nokia Developer Moderator ltomuta's Avatar
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,335
    Running virtually the same code:
    Code:
        qDebug() << "App dir: " << QApplication::applicationDirPath();
        qDebug() << "Exists: " << QDir(QApplication::applicationDirPath()).exists(); // false
    I get:
    Executable file: 9972 2011-04-19T14:40:09 C:\QtSDK\Symbian\SDKs\Symbian3Qt473\epoc32\release\armv5\udeb\TestAppDir.exe
    Starting application...
    Application running with pid 836.
    [Qt Message] App dir: "C:/Private/e07ccd81"
    [Qt Message] Exists: true
    So the behaviour of the APIs is correct, although:
    a) the directory may or may not exist and that may or may not be relevant
    b) if the directory does not exists, you may have to create it
    c) it would appeat that Qt does create that directory for one reason or another when the application is first started. That does not mean that you should also use it, for example you may want to use e:/Private/e07ccd81, a directory which is equaly valid but very likely not to exist by default if the app is installed on C:\

  7. #7
    Registered User H0LL0's Avatar
    Join Date
    Nov 2010
    Posts
    38
    The directory returned by QApplication::applicationDirPath() definetly DOES exist on application creation. (it is C:\private\<uid>) i can write files in it. i can read files from it. i can NOT create directories in it.

    The dir seperator is "\\" as it should be. (although that doesnt matter, since qt corrects wrong seperators on file access)

    the version.txt is shipped with the application and is included correctly in the .sis file. the target is !:\private\<uid>\version.txt and the application is installed to C: and as i said i can read that file.

    i work on a nokia e66 (s60 3rd FP1)

  8. #8
    Nokia Developer Moderator ltomuta's Avatar
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,335
    That is not what you have asked for in the previous post. Anyway, creating a subdirectory works and exist() returns true when executed on it later.

  9. #9
    Registered User H0LL0's Avatar
    Join Date
    Nov 2010
    Posts
    38
    ok, i tested a little again and to make my point clear here is my code:

    Code:
    	QDir appDir(QApplication::applicationDirPath());
    	QString fileName = QApplication::applicationDirPath() + "/version.txt";
    	QFile testFile(fileName);
    
    	qDebug() << "App dir:" << QApplication::applicationDirPath();
    	qDebug() << "AppDir Exists:" << appDir.exists();
    	qDebug() << "File:" << fileName;
    	qDebug() << "File Exists:" << QFile::exists(fileName);
    	qDebug() << "Copy:" << testFile.copy(QApplication::applicationDirPath() + "/test.txt");
    	qDebug() << "Copy in Subdir:" << testFile.copy(QApplication::applicationDirPath() + "/test/test.txt");
    	qDebug() << "Subdir Exists:" << QDir(QApplication::applicationDirPath() + "/test").exists();
    	qDebug() << "mkpath Subdir" << QDir().mkpath(QApplication::applicationDirPath() + "/test");
    	qDebug() << "mkdir Subdir:" << appDir.mkdir("test");
    	qDebug() << "Subdir Exists:" << QDir(QApplication::applicationDirPath() + "/test").exists();
    	qDebug() << "Copy in Subdir:" << testFile.copy(QApplication::applicationDirPath() + "/test/test.txt");
    Output:

    [Qt Message] App dir: "C:/Private/e68fb921"
    [Qt Message] AppDir Exists: false
    [Qt Message] File: "C:/Private/e68fb921/version.txt"
    [Qt Message] File Exists: true
    [Qt Message] Copy: true
    [Qt Message] Copy in Subdir: false
    [Qt Message] Subdir Exists: false
    [Qt Message] mkpath Subdir false
    [Qt Message] mkdir Subdir: true
    [Qt Message] Subdir Exists: true
    [Qt Message] Copy in Subdir: true
    Unexpected behaviour: not working mkpath and not working exists() function on the path. still looks like a qt bug to me.

  10. #10
    Registered User H0LL0's Avatar
    Join Date
    Nov 2010
    Posts
    38
    I tested it on Qt 4.7.3 now it doesnt work either.

  11. #11
    Registered User laa-laa's Avatar
    Join Date
    Aug 2003
    Location
    Oulu, Finland
    Posts
    1,122
    It's a feature of Symbian and not really a bug. The reason is already there in post #5: \private directory itself is not accessible (without AllFilles capability) while \private\youruid is. Checking for file or dir existence requires access to the directory where the file or subdir resides.

  12. #12
    Nokia Developer Moderator ltomuta's Avatar
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,335
    Testing on the application directory and its content should work just fine. Well, not just should, it actually does. This is what I get running the same code on E7

    Code:
    [Qt Message] App dir: "C:/Private/e07ccd81" 
    [Qt Message] AppDir Exists: true 
    [Qt Message] File: "C:/Private/e07ccd81/version.txt" 
    [Qt Message] File Exists: false 
    [Qt Message] Copy: false 
    [Qt Message] Copy in Subdir: false 
    [Qt Message] Subdir Exists: false 
    [Qt Message] mkpath Subdir true 
    [Qt Message] mkdir Subdir: false 
    [Qt Message] Subdir Exists: true 
    [Qt Message] Copy in Subdir: false
    It is strange that you are getting false there. What phone are you using for testing?

    The rest of the results also appear to be correct as you are doing a lot of operations with testFile, a file which does not exist and is never created.
    Then makepath succeeds while mkdir, called to create an existing subdirectory, fails.

  13. #13
    Registered User H0LL0's Avatar
    Join Date
    Nov 2010
    Posts
    38
    Hmm ok. So it seems to be a Symbian Security issue. It is trange that Qt behaves different on different Symbian platforms, though. I develop on a Nokia E66 (S60 3rd FP1).

  14. #14
    Nokia Developer Moderator ltomuta's Avatar
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,335
    If Qt really behaves differently then it is a bug and you should report it at http://bugreports.qt.nokia.com
    I'll see if I can find a 3.1 device where I can test it, but that's unlikely, so please do create a bug report based on your current findings.

  15. #15
    Registered User H0LL0's Avatar
    Join Date
    Nov 2010
    Posts
    38
    http://bugreports.qt.nokia.com/browse/QTBUG-18944

    i hope to get my hands on another 3.1 device soon, too.

Similar Threads

  1. Simulator returns window.navigator.onLine as false
    By somms in forum Symbian Web Runtime
    Replies: 1
    Last Post: 2011-02-09, 11:55
  2. QDir::count () returns strange number
    By kongkong163 in forum Qt
    Replies: 3
    Last Post: 2010-10-28, 11:36
  3. Replies: 1
    Last Post: 2009-11-20, 20:46
  4. Why ViewShown function always returns False?
    By kamalakshan in forum Symbian C++
    Replies: 3
    Last Post: 2009-05-20, 15:12
  5. Replies: 5
    Last Post: 2009-03-31, 12:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved