Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't start separate event loop for QFileDialog #16158

Merged
merged 1 commit into from
Jan 20, 2022

Conversation

glassez
Copy link
Member

@glassez glassez commented Jan 17, 2022

It conflicts with QMenu on Qt6 that causes the crash.

Closes #15779.

@glassez glassez added GUI GUI-related issues/changes Qt6 compat Make codebase more compatible with Qt6 labels Jan 17, 2022
@glassez glassez added this to the 4.4.1 milestone Jan 17, 2022
@glassez glassez requested review from Chocobo1, xavier2k6 and a team January 17, 2022 13:00
xavier2k6
xavier2k6 previously approved these changes Jan 17, 2022
@xavier2k6
Copy link
Member

tested - confirm, fixed.

src/gui/transferlistwidget.cpp Outdated Show resolved Hide resolved
src/gui/transferlistwidget.cpp Outdated Show resolved Hide resolved
torrent->setAutoTMMEnabled(false);
torrent->setSavePath(Utils::Fs::expandPathAbs(newLocation));
}
const QVector<BitTorrent::Torrent *> torrents = getSelectedTorrents();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for discussion (not a hard blocker):
Formally speaking this is the wrong approach (and this problem plague all GUI code). Is there a better way of solving it?
I suppose it can record a list of infohash instead and resolve it to torrent handle later when needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can have TorrentPtr like QPointer, which automatically becomes null when the torrent is removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formally speaking this is the wrong approach (and this problem plague all GUI code).

The real wrong case is passing QModelIndex (or Torrent *) list to asynchronous handler (since they can be invalidated in between).
I don't do this here.

Copy link
Member

@Chocobo1 Chocobo1 Jan 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can have TorrentPtr like QPointer, which automatically becomes null when the torrent is removed?

The idea is good, but how would the implementation look like? or is it even feasible?

The real wrong case is passing QModelIndex (or Torrent *) list to asynchronous handler (since they can be invalidated in between).

The invalidated entries will be discarded while the rest (valid) entries will still apply the action.

Copy link
Member Author

@glassez glassez Jan 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real wrong case is passing QModelIndex (or Torrent *) list to asynchronous handler (since they can be invalidated in between).

The invalidated entries will be discarded while the rest (valid) entries will still apply the action.

Seems you misunderstood me.
If you store pointers you can't know which of them are invalid. So you should either store Torrent IDs and then try to obtain corresponding torrents or store QPointers and check them for nullptr. Or obtain selected items in handler (as I'm done).

but how would the implementation look like?

Make Torrent to inherit QObject and store QPointers.

Copy link
Member

@Chocobo1 Chocobo1 Jan 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you store pointers you can't know which of them are invalid. So you should either store Torrent IDs and then try to obtain corresponding torrents or store QPointers and check them for nullptr. Or obtain selected items in handler (as I'm done).

That is why I said storing the infohash instead.

Make Torrent to inherit QObject and store QPointers.

That probably will do.

But obtaining selected items in handler seems more ergonomic to me (than store the list and then check its item).

AFAIK it might be possible that before the asynchronous handler took action the user reselected the torrents, even the timing window is very small this way (obtaining selected items in handler) is still wrong IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the user reselected the torrents, even the timing window is very small this way (obtaining selected items in handler)

Even if the user has time to click something at this time (during executing of discussed handler), this event (selecting/deselecting torrents) will be processed only after processing the current one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if the user has time to click something at this time (during executing of discussed handler), this event (selecting/deselecting torrents) will be processed only after processing the current one.

I don't think so, the handler is connected to QDialog::accepted and a lot of things can happen before the signal is triggered...
Although the dialog is made modal so users cannot really reselect torrents but I still don't consider this code robust as it isn't a general pattern for all dialogs (including non-modal ones).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the handler is connected to QDialog::accepted and a lot of things can happen before the signal is triggered

Handlers (slots) are called directly unless "queued connection" is used.

Although the dialog is made modal so users cannot really reselect torrents

Yes, it is.

it isn't a general pattern for all dialogs (including non-modal ones).

When you create some dialog that should affect some selection from other place non-modal so your intention is allowing the user to reconsider selection and apply dialog action to the final one (otherwise making dialog non-modal is meaningless/confusing). So it seems to be general pattern for all dialogs affecting some selection.

Copy link
Member

@Chocobo1 Chocobo1 Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handlers (slots) are called directly unless "queued connection" is used.

I meant (generally speaking) a lot of UI events, background automatic processing, etc. could happen.

When you create some dialog that should affect some selection from other place non-modal so your intention is allowing the user to reconsider selection and apply dialog action to the final one (otherwise making dialog non-modal is meaningless/confusing). So it seems to be general pattern for all dialogs affecting some selection.

It would be correct only if the dialog says you can reselect the entries, which is not the case for most actions. This idea is not implied by dialogs (by default), which would be counter-intuitive.

otherwise making dialog non-modal is meaningless/confusing

Making dialog non-modal has other meanings, not just limited to this one.

It conflicts with QMenu on Qt6 that causes the crash.
@xavier2k6
Copy link
Member

re-tested with latest commit & all ok.

@glassez glassez merged commit 5d69334 into qbittorrent:master Jan 20, 2022
@glassez glassez deleted the fix-15779 branch January 20, 2022 04:22
glassez added a commit to glassez/qBittorrent that referenced this pull request Jan 21, 2022
It conflicts with QMenu on Qt6 that causes the crash.

PR qbittorrent#16158.
glassez added a commit that referenced this pull request Jan 22, 2022
It conflicts with QMenu on Qt6 that causes the crash.

PR #16158.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI GUI-related issues/changes Qt6 compat Make codebase more compatible with Qt6
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash after moving files in 4.4.0rc1
4 participants