[SOLVED]just a line of code



  • @QDir path( "./plugins" );@
    what's the meaning of "./" ?Where is the reference document of "./" and that's what syntax?



  • "./" (Linux/Unix) or "." (Windows) refers to the current directory.

    That is standard syntax for paths and comes from the underlying operating system, it's not Qt-specific.

    The same way "../" or ".." refers to the parent directory of the current directory.

    And "/" refers to the root of the file system hierarchy (Linux/Unix only).

    The only path prefix that is specific to Qt is ":/", which refers to the built-in Qt resources of your app...

    [EDIT]

    BTW: I much prefer to NOT trust on the current directory, but instead get the executable's location, i.e. the individual install path of your app, via qApp->applicationDirPath() and then do stuff relative to that directory.

    That's because the "current" directory may be misleading, depending on how your app had been launched.



  • Thank you very much.I'm using Windows 7 now,so I should use @QDir path( ".\plugins" );@ right?


  • Moderators

    No, Qt always uses the Unix convention internally. All paths passed to QDir, QFile, QFileInfo, QML etc. should be separated by '/'. Although in many cases Qt will correct the path if you put it in wrongly.



  • Side note: QDir::fromNativeSeparators() and QDir::toNativeSeparators() can be helpful to convert paths between the notation of your individual platform and Qt's internal (Unix-style) notation.

    [quote author="nimingzhe2008" date="1353329804"]Thank you very much.I'm using Windows 7 now,so I should use @QDir path( ".\plugins" );@ right?
    [quote]No, Qt always uses the Unix convention internally. All paths passed to QDir, QFile, QFileInfo, QML etc. should be separated by ‘/’. Although in many cases Qt will correct the path if you put it in wrongly.[/quote][/quote]

    Maybe, even better, you should use:
    @QDir path(QString("%1/plugins").arg(qApp->applicationDirPath()));@

    Assuming that your "plugins" sub-folder is located in the same folder as the main EXE file.

    BTW: even if you did use a back-slash (which you should not do), you'd have to write \ instead of ** - otherwise you create a \p escape-character, which I think is undefined and certainly not what you want ;-)



  • Thank you all.I have a try and indeed only the Unix convention works.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.