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. QUrl of "My Computer" ?
Forum Updated to NodeBB v4.3 + New Features

QUrl of "My Computer" ?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.8k 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.
  • H Offline
    H Offline
    HornetMaX
    wrote on last edited by
    #1

    Hi,
    I'm using some QUrls to populate the sidebar of a (non native) QFileDialog:

    @
    QFileDialog fd(this);
    fd.setAcceptMode(QFileDialog::AcceptOpen);
    fd.setFileMode(QFileDialog::ExistingFiles);
    fd.setNameFilter(QString("%1 (*%2)").arg(tr("Runs info")).arg(MAXTM_INFO_EXT_BIN));
    fd.setViewMode(QFileDialog::Detail);
    fd.setOption(QFileDialog::DontUseNativeDialog);
    // Set URLs for nice sidebar appearance.
    QList<QUrl> urls;
    urls << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation))
    << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))
    << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation))
    << QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
    fd.setSidebarUrls(urls);
    @

    All the above works fine (under Win 7, Qt 5.3), but what if I want to add the equivalent of "My Computer" ? I.e. the "folder" above the drives C:, D; etc.

    MaX.

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

      “My Computer” is not a real folder, it is more a graphical representation of disk management. So it does not have a path or URL. It is somewhat similar to "/" (aka the "root" directory) on Unix-like system, but still not the same! Under Windows there is no such thing as a common "root" directory where all the drives are mounted. Instead each drive has its own separate "root" directory - and the drive letter prefix, such as "C:", is used to specify the drive.

      Note that there is QDir::rootPath(), which returns "/" on Unix-like Systems. But on Windows it will return the root directory of the system drive, usually "C:".

      --

      More technically, the "My Computer" virtual folder is identified by a CSIDL (constant special item ID list). Some CSIDL's can be translated into a corresponding path, yes, but I don't think that is true for CSIDL_DRIVES.

      See also:

      • http://goo.gl/jLSX1
      • http://goo.gl/mmitpi

      [quote]CSIDL_DRIVES

      The virtual folder that represents My Computer, containing everything on the local computer: storage devices, printers, and Control Panel. The folder can also contain mapped network drives.[/quote]

      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
      • H Offline
        H Offline
        HornetMaX
        wrote on last edited by
        #3

        Thanks for the reply. Just for fun, I tried this:

        @QUrl::fromLocalFile("")@

        and it just works fine ! Nice icon in the sidebar, named "My Computer". nice start for a Tuesday morning :)

        MaX.

        1 Reply Last reply
        1
        • H Offline
          H Offline
          HeatherKM
          wrote on last edited by
          #4

          MaX,

          Just wanted to say Thanks! for the helpful hint. We are switching from the static QFileDialog functions to a class instance due to the need for extra checkboxes, and the loss of "My Computer" was driving me crazy! You've made my day!

          Heather

          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