Important: Please read the Qt Code of Conduct -

QUrl of "My Computer" ?

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

    QFileDialog fd(this);
    fd.setNameFilter(QString("%1 (*%2)").arg(tr("Runs info")).arg(MAXTM_INFO_EXT_BIN));
    // 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));

    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.


  • “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:


    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]

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


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


  • 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!


Log in to reply