QEvent
has been disabled in Qt 6.0.0.
Getting ready to Qt 6 (3/n). Do not use QKeyEvent
copy constructor
#580
pull
hebasto
wants to merge
1
commits into
bitcoin-core:master
from
hebasto:220409-event
changing
1
files
+5 −6
-
hebasto commented at 8:17 am on April 9, 2022: member
-
shaavan approved
-
shaavan commented at 5:43 pm on April 10, 2022: contributor
ACK d543515e635786214215e5b30a2874c4e8a676dc
- I was able to verify that with Qt 6, the copying of QEvent has been disabled. See for reference {second and third paragraph}.
- Therefore, instead of copying the key event, this PR uses its data to create a new event.
nit:
As a minor nit, I would suggest creating a variable
type
instead of callingkeyevt→type()
multiple times.0QEvent::Type type = keyevt->type()
-
hebasto force-pushed on Apr 10, 2022
-
in src/qt/rpcconsole.cpp:614 in 8691a444ad outdated
609@@ -610,6 +610,7 @@ bool RPCConsole::eventFilter(QObject* obj, QEvent *event) 610 if(event->type() == QEvent::KeyPress) // Special key handling 611 { 612 QKeyEvent *keyevt = static_cast<QKeyEvent*>(event); 613+ const auto type = keyevt->type(); 614 int key = keyevt->key(); 615 Qt::KeyboardModifiers mod = keyevt->modifiers();
shaavan commented at 7:48 am on April 11, 2022:Since we are refactoring this part of the code, how about we initialize the
key
andmod
variables as const since they are unchanged in their lifetime.0 const int key = keyevt->key(); 1 const auto mod = keyevt->modifiers();
hebasto commented at 8:13 am on April 11, 2022:Ok, I’ll implement this suggestion if/when other changes will be required.shaavan approvedshaavan commented at 7:48 am on April 11, 2022: contributorreACK 8691a444add29d62dade34bf2965cf76a5d6c863
Changes since my last review:
- Declared a
type
variable beforehand and used it instead ofkeyevt→type()
.
hebasto added the label Qt 6 on Apr 12, 2022luke-jr commented at 3:04 am on April 13, 2022: memberWhy are we creating a new event instead of forwarding the original one on? Seems like this PR would simply be bypassing the behaviour Qt is trying to prevent…hebasto commented at 8:05 am on April 13, 2022: memberWhy are we creating a new event instead of forwarding the original one on? Seems like this PR would simply be bypassing the behaviour Qt is trying to prevent…
The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been posted. It is not safe to access the event after it has been posted.
“forwarding the original one on” ends with double deletion of an
QKeyEvent
instance.luke-jr commented at 4:51 pm on April 13, 2022: memberHmm, how about using https://doc.qt.io/qt-5/qcoreapplication.html#sendEvent ?qt: Do not use `QKeyEvent` copy constructor
This change is preparation for Qt 6, and it fixes an experimental build with Qt 6.2.4 as copying of `QEvent` has been disabled in Qt 6.0.0 (see 19f9b0d5f54379151eb71e98555b203ad6756276 upstream commit).
hebasto force-pushed on Apr 13, 2022w0xlt approvedw0xlt commented at 10:14 pm on April 18, 2022: contributortACK https://github.com/bitcoin-core/gui/pull/580/commits/3ec6504a2e5b4afb7a2719a82191e0b96fe23214 on Ubuntu 21.10, Qt 5.15.2shaavan approvedshaavan commented at 12:14 pm on April 19, 2022: contributorreACK 3ec6504a2e5b4afb7a2719a82191e0b96fe23214
Changes since my last review:
- Instead of creating a new event for each call of postEvent, send Event is used with keyevt event.
Since sendEvent does not delete the event argument after the completion of its execution, the same keyevt could be used multiple times instead of creating a separate event for each instance of using postEvent. Therefore I agree with this change.
References:
- postEvent: https://doc.qt.io/qt-6/qcoreapplication.html#postEvent
- sendEvent: https://doc.qt.io/qt-6/qcoreapplication.html#sendEvent
- Comparison between the two: https://doc.qt.io/archives/qq/qq11-events.html (under section Synthetic Events)
hebasto merged this on Apr 19, 2022hebasto closed this on Apr 19, 2022
hebasto deleted the branch on Apr 19, 2022sidhujag referenced this in commit 1fcb269d44 on Apr 19, 2022bitcoin-core locked this on Apr 19, 2023
This is a metadata mirror of the GitHub repository bitcoin-core/gui. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 12:20 UTC
More mirrored repositories can be found on mirror.b10c.me