View Single Post
Old 07-29-2025, 05:35 AM   #3
BeckyEbook
Guru
BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.
 
BeckyEbook's Avatar
 
Posts: 876
Karma: 3501146
Join Date: Jan 2017
Location: Poland
Device: Various
I admit that I also like the native system window, so I played around with simple filtering and in Windows it works.

I know that `QFileDialog::DontUseNativeDialog` is safer, but let's be honest: how many people are going to type in the graphics link instead of pointing to the appropriate file from disk?

Such code works for me.
So I leave the condition only Q_OS_MAC and check the beginning of the path. If http/https then I display a message, but with no crash.

Code:
    QFileDialog::Options options = QFileDialog::Options();
#if defined(Q_OS_MAC)
    options = options | QFileDialog::DontUseNativeDialog;
#endif

    // tempfilepaths are full absolute file paths to the files to be added
    QStringList tempfilepaths = QFileDialog::getOpenFileNames(this,
        tr("Add Existing Files"),
        m_LastFolderOpen,
        filter_string,
        NULL,
        options);

    QStringList filepaths;
    for (const QString &path : tempfilepaths) {
    if (path.startsWith("http://", Qt::CaseInsensitive)
     || path.startsWith("https://", Qt::CaseInsensitive)) {
        Utility::DisplayStdErrorDialog(
            tr("The path \"%1\" is not a local file and was not added.").arg(path));
        continue;
    }
        filepaths << path;
    }
Such a preliminary check of the existence of links should be enough, and Windows users will not turn their noses up at the default Qt window.
BeckyEbook is online now   Reply With Quote