Results 1 to 4 of 4

Thread: QDir Path problem

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question QDir Path problem

    I have a program that attempts to save a file in a predetermined directory if it exists, otherwise the user is prompted where to save the file to.

    The file is of a very specific naimg convention of #####XX###X.txt where #=number and X=letter.

    There is also a corresponding directory located at "/someDir/anotherDir/aThirdDir/#####XX###X/manySubDirs". The #s and Xs in the filename are the same as in the directory so they match 100%.

    Now sometimes the directory may be listed as aThirdDir/#####XX###X_XXX where the creator of the directory puts their initials at the end of the directory listing. I am trying to save the file in "/someDir/anotherDir/aThirdDir/#####XX###X_XXX/oneSubDir/". So I get the environment variable that holds "/someDir/anotherDir/aThirdDir/" and then append the #####XX###X to this directory listing. What I want to do then is append a "*" after the common name so if the _XXX part is there it will know to include this in the directory string. You can "cd" in this manner in a unix terminal window but it appears when I attempt to use the

    Qt Code:
    1. QDir::isAbsolutePath( QString( "/someDir/anotherDir/aThirdDir/#####XX###X*/oneSubDir" ) );
    To copy to clipboard, switch view to plain text mode 

    It says the directory doesn't exist. Is there a way to get the QDir to know the * means a wildcard character and not the actual * character? Sorry for the long-winded explanation, but I thought a background on my problem could help find a solution. Thanks!

  2. #2
    Join Date
    Jul 2007
    Posts
    30
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDir Path problem

    You will have to code your own little "*" wildcard.
    Which isn't really too hard.
    Loop through all the Dirs, and pick the first one that matches closely enough.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDir Path problem

    There is QAbstractFileEngineHandler which can do exactly what you want:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class WildcardEngineHandler : public QAbstractFileEngineHandler
    4. {
    5. public:
    6. QAbstractFileEngine* create(const QString& fileName) const;
    7. };
    8.  
    9. QAbstractFileEngine* WildcardEngineHandler::create(const QString& fileName) const
    10. {
    11. if (fileName matches the pattern)
    12. {
    13. // fill in place holders in the name
    14. return new QFSFileEngine(actualFileName);
    15. }
    16. return 0;
    17. }
    18.  
    19. int main(int argc, char **argv)
    20. {
    21. QApplication app(argc, argv);
    22. WildcardEngineHandler engine;
    23.  
    24. ...
    25.  
    26. return app.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    ToddAtWSU (21st August 2008)

  5. #4
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDir Path problem

    I will give this a try. Was out of town the past 2 weeks and just now got a chance to look back into this. Thanks!

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Problem to find file path
    By phillip_Qt in forum Qt Programming
    Replies: 14
    Last Post: 28th April 2008, 10:06
  3. Qt4 plugin path problem
    By david.corinex in forum Installation and Deployment
    Replies: 6
    Last Post: 5th January 2008, 16:10
  4. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  5. How to explicitely delete a QDir?
    By alan in forum Newbie
    Replies: 2
    Last Post: 13th February 2006, 17:48

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.