Results 1 to 4 of 4

Thread: Strange File Path Issue

  1. #1
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Strange File Path Issue

    I have reworked a Qt program that was originally in Windows such that it would work properly in both Windows and Linux.

    Part of my code is designed to write a file in the program's directory:

    Qt Code:
    1. QDir::setCurrent(QCoreApplication::applicationDirPath());
    2.  
    3. QFile file(filename); //open the file:
    4. if (file.open(QFile::WriteOnly)) {
    5. qDebug() << "File open: " << filename;
    6. file.write(filedata);
    7. file.close();
    8. } else {
    9. qDebug() << "File not open: " << filename;
    10. }
    To copy to clipboard, switch view to plain text mode 

    On windows, this code would create the file in the directory of the program
    On linux 2 results happen:
    --- If I click on the application in Konqueror or Dolphin, then the file is created in my home directory rather than where the executable is, seemingly ignoring the QDir
    --- if I open a terminal and type "./myprogram" then the program creates the file in the directory of the program like it should.

    Why would this happen, and how could I make the file always be created in the directory of the executable regardless of if its opened through the file manager or the command line?

    I am using Qt 4.4.3 on an Ubuntu Intrepid and Windows XP systems.

  2. #2
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange File Path Issue

    nvm, I guess this is a known bug in KDE, which the file manager forces the default working directory to be home unless you make a link to the file and change the working directory that way or run from the command line.

  3. #3
    Join Date
    Oct 2006
    Location
    Hawaii
    Posts
    130
    Thanks
    48
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange File Path Issue

    Qt Code:
    1. QFile file(qApp->applicationDirPath() + "/" + filename); //open the file:
    2. if (file.open(QFile::WriteOnly)) {
    3. qDebug() << "File open: " << filename;
    4. file.write(filedata);
    5. file.close();
    6.  
    7. } else {
    8. qDebug() << "File not open: " << filename;
    9. }
    To copy to clipboard, switch view to plain text mode 
    did the trick

  4. #4
    Join Date
    May 2007
    Posts
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange File Path Issue

    Yes , you are right. This is known bug in KDE:

    http://bugs.kde.org/show_bug.cgi?id=131010

    There is a solution(it's not user friendly but...)

Similar Threads

  1. File path issue...
    By kaushal_gaurav in forum Qt Programming
    Replies: 9
    Last Post: 1st October 2008, 16:36
  2. Re: Opening Project file Issue in Edyuk
    By philwinder in forum Qt-based Software
    Replies: 6
    Last Post: 5th May 2008, 21:49
  3. qt3 to qt4 - uic issue
    By hvengel in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2007, 03:59
  4. Replies: 5
    Last Post: 22nd September 2006, 09:04
  5. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 11:28

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.