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

Codebase: emiting a signal forcedly from outside is a bad practice #540

Open
asashnov opened this issue Nov 23, 2020 · 15 comments · Fixed by #751
Open

Codebase: emiting a signal forcedly from outside is a bad practice #540

asashnov opened this issue Nov 23, 2020 · 15 comments · Fixed by #751
Assignees
Milestone

Comments

@asashnov
Copy link
Contributor

asashnov commented Nov 23, 2020

kiwix-desktop 'master' (830e19b)

Found during working on #454

From src/zimview.cpp:

emit mp_tabBar->currentTitleChanged(str);
emit mp_tabBar->currentZimIdChanged(zimId);
emit mp_tabBar->webActionEnabledChanged(QWebEnginePage::Back, mp_webView->isWebActionEnabled(QWebEnginePage::Back));
emit mp_tabBar->webActionEnabledChanged(QWebEnginePage::Forward, mp_webView->isWebActionEnabled(QWebEnginePage::Forward));
emit mp_library->bookmarksChanged();

According to Qt documentation, this is a bad practice.
By signals, only the object itself should notify that its internal state has changed:

https://doc.qt.io/qt-5/signalsandslots.html

Signals
Signals are emitted by an object when its internal state has changed in some way that might be interesting to the object's client or owner. Signals are public access functions and can be emitted from anywhere, but we recommend to only emit them from the class that defines the signal and its subclasses.

@kelson42
Copy link
Collaborator

@asashnov Fell free to propose an alternative if this helps to fix #454 or trivial to do.

@kelson42
Copy link
Collaborator

What could be an alternative approach?

@stale
Copy link

stale bot commented Mar 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions.

@stale stale bot added the stale label Mar 19, 2021
@asashnov
Copy link
Contributor Author

Good approach is suggested by Qt documentation:

Signals are emitted by an object when its internal state has changed

we recommend to only emit them from the class that defines the signal

It is even possible to connect a signal directly to another signal

All classes that inherit from QObject or one of its subclasses (e.g., QWidget) can contain signals and slots. Signals are emitted by objects when they change their state in a way that may be interesting to other objects. This is all the object does to communicate. It does not know or care whether anything is receiving the signals it emits. This is true information encapsulation, and ensures that the object can be used as a software component.

@stale stale bot removed the stale label Jun 15, 2021
asashnov added a commit that referenced this issue Jun 16, 2021
Fix potential memory leak: passing ZimView as a parent QObject
to WebView makes WebView to be destroyed automatically with ZimView.

Signal currentZimIdChanged() isn't used anywhere, removed from code.
asashnov added a commit that referenced this issue Jun 16, 2021
Fix potential memory leak: passing ZimView as a parent QObject
to WebView makes WebView to be destroyed automatically with ZimView.

Signal currentZimIdChanged() isn't used anywhere, removed from code.
asashnov added a commit that referenced this issue Jun 16, 2021
Signal currentZimIdChanged() isn't used anywhere, removed from code.
kelson42 pushed a commit that referenced this issue Jul 8, 2021
Signal currentZimIdChanged() isn't used anywhere, removed from code.
kelson42 added a commit that referenced this issue Jul 8, 2021
Partial fix of #540: do not emit others object signals.
@stale
Copy link

stale bot commented Sep 7, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions.

@stale stale bot added the stale label Sep 7, 2021
@stale stale bot removed the stale label Dec 17, 2021
@kelson42 kelson42 added this to the 2.1.0 milestone Dec 18, 2021
asashnov added a commit that referenced this issue Dec 20, 2021
…imView

as this is a bad practice according QObject documentation.
asashnov added a commit that referenced this issue Dec 20, 2021
…ZimView

as it's bad practice according to QObject documentation.
@kelson42 kelson42 modified the milestones: 2.1.0, 2.2.0 Dec 22, 2021
asashnov added a commit that referenced this issue Dec 29, 2021
…ZimView

as it's bad practice according to QObject documentation.
asashnov added a commit that referenced this issue Jan 7, 2022
…ZimView

as it's bad practice according to QObject documentation.
asashnov added a commit that referenced this issue Jan 13, 2022
…ZimView

as it's bad practice according to QObject documentation.
asashnov added a commit that referenced this issue Jan 18, 2022
…ZimView

as it's bad practice according to QObject documentation.
asashnov added a commit that referenced this issue Jan 26, 2022
The TabBar should only emit it themself when it comes from the current tab.
@kelson42 kelson42 modified the milestones: 2.3.0, 2.2.0 Feb 14, 2022
@kelson42
Copy link
Collaborator

@asashnov I rechallenge you on this: what is left to do?

@asashnov
Copy link
Contributor Author

kelson42@ Part3 would be illiminating emit mp_library->bookmarksChanged();

@kelson42 kelson42 modified the milestones: 2.2.0, 2.3.0 Feb 23, 2022
@stale
Copy link

stale bot commented Jun 13, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions.

1 similar comment
@stale
Copy link

stale bot commented Aug 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions.

@stale stale bot added the stale label Aug 14, 2022
@kelson42 kelson42 modified the milestones: 2.4.0, 2.5.0 Aug 12, 2023
@stale stale bot removed stale labels Aug 12, 2023
@kelson42 kelson42 moved this to TODO in GSOC 2024 May 3, 2024
@kelson42 kelson42 moved this from TODO to DOING in GSOC 2024 Jun 11, 2024
@kelson42
Copy link
Collaborator

kelson42 commented Jun 15, 2024

@shaopengLinCan we move forward on this issue while PR currently in review waits for the reviewer? Do you have an opinion or a proposal on this issue?

@ShaopengLin
Copy link
Collaborator

So the mp_library emits are needed because they were directly using the kiwix library that don't emit signals. I will do a PR soon and design decisions can happen there.

@kelson42
Copy link
Collaborator

@ShaopengLin Thank you. I have to admit that the rational behind this issue are not clear to me. So, trust you to understand it :)

@kelson42
Copy link
Collaborator

@veloman-yunkan Like proposed, can you please quickly implement the fix?

@veloman-yunkan
Copy link
Collaborator

@kelson42 That is absolutely not a priority for me now. Let's first release 2.4.0.

@kelson42 kelson42 modified the milestones: 2.5.0, 2.6.0 Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment