Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]just a line of code
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]just a line of code

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nimingzhe2008
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      "./" (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.

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nimingzhe2008
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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.

          (Z(:^

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MuldeR
            wrote on last edited by
            #5

            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 ;-)

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nimingzhe2008
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved