Important: Please read the Qt Code of Conduct -

QFileDialog::setSidebarUrls() not working

  • Hi everyone,

    I am trying to customize sidebars URLs in a non-native file dialog but I couldn't manage it. This is the code:

    QFileDialog *m_dialog = new QFileDialog(0, Qt::WindowStaysOnTopHint);
    QList<QUrl> urls;
    urls    << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).front())
                << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).front());

    The file dialog is displayed but the sidebars URLs are the default ones. I know the QUrl objects in the list are OK because I used them with QDesktopServices::openUrl() and everything was fine.

    After setting the new URLs, the method QFileDialog::sidebarUrls() returns an empty QList<QUrl>.

    I have tested this code with Qt 5.3.2 and on both Windows and Mac.

    What am I doing wrong?


  • Lifetime Qt Champion


    Current workaround: call setOption(QFileDialog::DontUseNativeDialog); before setSidebarUrls

  • @Cesius said:


    I do not see why do you think you use non-native dialog from the code.

    From documentation:
    "By default, a platform-native file dialog will be used if the platform has one."

    And there is no proper option set.

Log in to reply