qt: Assert QMetaObject::invokeMethod result #16348

pull promag wants to merge 2 commits into bitcoin:master from promag:2019-07-assert-invoke-method changing 8 files +47 −22
  1. promag commented at 4:22 pm on July 6, 2019: member

    Invalid/wrong dynamic calls aren’t verified by the compiler. This PR asserts those dynamic calls. Once we bump Qt to at least 5.10 these can be refactored to use the invokeMethod overload that allows connecting to lambdas or member pointers, which are compile checked.

    For reference, one of the overloaded versions is https://doc.qt.io/qt-5/qmetaobject.html#invokeMethod-5.

  2. promag force-pushed on Jul 6, 2019
  3. DrahtBot commented at 6:23 pm on July 6, 2019: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16349 (qt: Remove redundant WalletController::addWallet signal by hebasto)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. hebasto commented at 7:22 pm on July 6, 2019: member

    @promag

    Once we bump Qt to at least 5.10 these can be refactored to use the invokeMethod overload that allows connecting to lambdas or member pointers, which are compile checked.

    IMO, in the long run it will be better to get rid of QMetaObject::invokeMethod completely, because QMetaObject class

    … is not normally required for application programming…

  5. fanquake added the label GUI on Jul 6, 2019
  6. promag commented at 7:43 pm on July 6, 2019: member
    @hebasto since Qt 5.10 invokeMethod is very useful to run code (a)synchronous in other thread.
  7. hebasto commented at 8:35 am on July 7, 2019: member

    @promag

    since Qt 5.10 invokeMethod is very useful to run code (a)synchronous in other thread.

    I believe it is possible and convenient to handle all inter-thread communications via signal-slot connections. That is the main Qt feature ;)

  8. promag commented at 9:06 am on July 7, 2019: member
    Yes, but there’s nothing wrong with convenience, that’s why those were added.
  9. hebasto commented at 9:10 am on July 7, 2019: member
    Concept ACK
  10. laanwj commented at 2:19 pm on July 8, 2019: member
    So to be clear, before concept ACK: these can only fail when the name / method signature is wrong, not for run-time reasons such as a full queue ?
  11. promag commented at 2:25 pm on July 8, 2019: member

    @laanwj yes, from the docs:

    Invokes the member (a signal or a slot name) on the object obj. Returns true if the member could be invoked. Returns false if there is no such member or the parameters did not match.

    such as a full queue

    Is this even possible?

  12. laanwj commented at 3:31 pm on July 8, 2019: member

    Is this even possible?

    I don’t think so, not sure, my experience (with accidentally not rate-limiting notifications) is that the queue is very deep at least but thanks for quoting the doc that’s good enough for me.

    concept and code review ACK 2fd7d0b9081c9add34277e94e8ad21ce22ee2d61

  13. hebasto commented at 3:45 pm on July 8, 2019: member
    This approach was used in a720a983015c9ef8cc814c16a5b9ef6379695817 already.
  14. MarcoFalke added the label Refactoring on Jul 8, 2019
  15. hebasto commented at 4:19 pm on July 8, 2019: member

    Tested on Debian 9.9 (system Qt 5.7.1):

    0$ ./src/qt/bitcoin-qt -regtest -nowallet -debug=qt
    

    Open a wallet from menu…

    0bitcoin-qt: qt/walletcontroller.cpp:125: WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wallet>): Assertion `invoked' failed.
    1Aborted
    
    0$ tail -5 ~/.bitcoin/regtest/debug.log 
    12019-07-08T16:14:33Z [rpc one] nFileVersion = 189900
    22019-07-08T16:14:33Z [rpc one] Keys: 2001 plaintext, 0 encrypted, 2001 w/ metadata, 2001 total. Unknown wallet records: 0
    32019-07-08T16:14:33Z [rpc one] Wallet completed loading in              97ms
    42019-07-08T16:14:33Z GUI: TransactionTablePriv::refreshWallet
    52019-07-08T16:14:33Z GUI: QMetaMethod::invoke: Unable to handle unregistered datatype 'WalletModel*'
    

    Ref: #15453, #16349

  16. promag commented at 4:24 pm on July 8, 2019: member
  17. hebasto commented at 4:33 pm on July 8, 2019: member

    @promag

    please add WalletModel* … and test again.

    Done. No luck (( Result is the same.

  18. hebasto commented at 5:00 pm on July 8, 2019: member

    @promag the latter is enough:

     0diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
     1index 2fdbcca04..b7740d540 100644
     2--- a/src/qt/bitcoin.cpp
     3+++ b/src/qt/bitcoin.cpp
     4@@ -454,6 +454,7 @@ int GuiMain(int argc, char* argv[])
     5     qRegisterMetaType< CAmount >("CAmount");
     6     qRegisterMetaType< std::function<void()> >("std::function<void()>");
     7     qRegisterMetaType<QMessageBox::Icon>("QMessageBox::Icon");
     8+    qRegisterMetaType< WalletModel* >();
     9     /// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
    10     // Command-line options take precedence:
    11     node->setupServerArgs();
    

    It works.

  19. promag commented at 5:07 pm on July 8, 2019: member
    Cool, I’ll add it here and you can close your PR.
  20. hebasto commented at 5:20 pm on July 8, 2019: member

    @promag

    Cool, I’ll add it here and you can close your PR.

    I will leave it as refactoring, if you don’t mind.

  21. laanwj commented at 5:50 pm on July 8, 2019: member
    Nice that this helped find an actual bug!
  22. gui: Fix missing qRegisterMetaType(WalletModel*) f27bd96b5f
  23. qt: Assert QMetaObject::invokeMethod result 64fee48944
  24. promag force-pushed on Jul 8, 2019
  25. promag commented at 0:39 am on July 9, 2019: member
    IMO all done here, thanks @hebasto.
  26. hebasto commented at 4:58 am on July 9, 2019: member
    ACK f27bd96b5fdc2921d93c44bbf422bff0e979c4de, I have tested the code.
  27. laanwj commented at 9:47 am on July 9, 2019: member

    @hebasto looks like you didn’t ACK the top commit but the one below it

    ACK 64fee489448c62319e77941c30152084695b5a5d

  28. laanwj merged this on Jul 9, 2019
  29. laanwj closed this on Jul 9, 2019

  30. laanwj referenced this in commit 8046a3e0be on Jul 9, 2019
  31. hebasto commented at 9:54 am on July 9, 2019: member

    @hebasto looks like you didn’t ACK the top commit but the one below it

    post-merge ACK 64fee489448c62319e77941c30152084695b5a5d

  32. promag deleted the branch on Jul 9, 2019
  33. laanwj added the label Needs backport on Jul 9, 2019
  34. laanwj added this to the milestone 0.18.1 on Jul 9, 2019
  35. promag referenced this in commit e2f7677bde on Jul 9, 2019
  36. promag referenced this in commit df695db323 on Jul 9, 2019
  37. promag commented at 1:19 pm on July 9, 2019: member
    Backport in #16359.
  38. fanquake removed the label Needs backport on Jul 9, 2019
  39. MarcoFalke removed the label Refactoring on Jul 9, 2019
  40. pull[bot] referenced this in commit 9059a6f248 on Aug 12, 2019
  41. sidhujag referenced this in commit 4bea2828a2 on Aug 13, 2019
  42. HashUnlimited referenced this in commit afc969c82b on Aug 23, 2019
  43. HashUnlimited referenced this in commit b744f25285 on Aug 23, 2019
  44. Bushstar referenced this in commit 2da5dbdf37 on Aug 24, 2019
  45. Bushstar referenced this in commit 91f1510196 on Aug 24, 2019
  46. Bushstar referenced this in commit 97a0c7b2db on Aug 24, 2019
  47. Bushstar referenced this in commit 17df7b1c7b on Aug 24, 2019
  48. Bushstar referenced this in commit 9f4dbfb981 on Aug 24, 2019
  49. Bushstar referenced this in commit 50d1d4ef3d on Aug 24, 2019
  50. Bushstar referenced this in commit b5857a4cd3 on Aug 24, 2019
  51. Bushstar referenced this in commit 63fd04187f on Aug 24, 2019
  52. laanwj referenced this in commit 89e93135ae on Nov 10, 2019
  53. laanwj referenced this in commit 0038e536de on Jan 22, 2020
  54. deadalnix referenced this in commit 046c789d43 on May 21, 2020
  55. deadalnix referenced this in commit 05693cef84 on May 21, 2020
  56. ShengguangXiao referenced this in commit 66d822db4b on Aug 28, 2020
  57. PastaPastaPasta referenced this in commit 35dac7a968 on Sep 21, 2021
  58. PastaPastaPasta referenced this in commit e95c6e0853 on Sep 24, 2021
  59. kittywhiskers referenced this in commit 8ce73d7b56 on Oct 12, 2021
  60. PastaPastaPasta referenced this in commit cb93b86556 on Nov 1, 2021
  61. Munkybooty referenced this in commit 158061f4f2 on Nov 25, 2021
  62. Munkybooty referenced this in commit eedd48926c on Nov 30, 2021
  63. DrahtBot locked this on Dec 16, 2021


promag DrahtBot hebasto laanwj

Labels
GUI

Milestone
0.18.1


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-06 01:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me