Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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.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.



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

    [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]



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



  • 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


Log in to reply