Advertisement
Guest User

Untitled

a guest
Feb 14th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.  
  6. <link rel="stylesheet" href="file:///android_asset/bootstrap.min.css">
  7.  
  8. <!-- that's a special resource with JS-library for WebChannel -->
  9. <script type="text/javascript" src="file:///android_asset/qwebchannel.js"></script>
  10.  
  11. <script type="text/javascript">
  12.  
  13. // here will be our QtObject from QML side
  14. var backend;
  15.  
  16. window.onload = function()
  17. {
  18. new QWebChannel(qt.webChannelTransport, function(channel) {
  19. // all published objects are available in channel.objects under
  20. // the identifier set in their attached WebChannel.id property
  21. backend = channel.objects.backend;
  22.  
  23. // connect to a signal
  24. backend.someSignal.connect(function(someText) {
  25. alert("Got signal: " + someText);
  26. document.getElementById("lbl").innerHTML = someText;
  27. });
  28. });
  29. }
  30.  
  31. // just to demonstrate you async interaction
  32. var result = "ololo";
  33. function changeLabel()
  34. {
  35. var textInputValue = document.getElementById("input").value.trim();
  36. if (textInputValue.length === 0)
  37. {
  38. alert("You haven't entered anything!");
  39. return;
  40. }
  41.  
  42. // invoke a method, and receive the return value asynchronously
  43. backend.changeText(textInputValue, function(callback) {
  44. //processThisShit(callback);
  45. result = callback;
  46. // since it's async, this alert will appear later and show the actual result
  47. alert(result);
  48. // reset variable back to default value
  49. result = "ololo";
  50. });
  51. // this alert will appear first and show default "ololo"
  52. alert(result);
  53. }
  54.  
  55. //function processThisShit(shit) {
  56. // //alert("Shit has been processed. " + shit);
  57. // result = shit;
  58. // alert(result);
  59. //}
  60.  
  61. // you can also read/write properties of QtObject from QML side
  62. function getPropertyValue()
  63. {
  64. var originalValue = backend.someProperty;
  65.  
  66. alert(backend.someProperty);
  67. backend.someProperty = "some another value";
  68. alert(backend.someProperty);
  69.  
  70. backend.someProperty = originalValue;
  71. }
  72.  
  73. </script>
  74.  
  75. <style>
  76. div.centered {
  77. position: absolute;
  78. top: 50%;
  79. left: 50%;
  80. transform: translateX(-50%) translateY(-50%);
  81. }
  82. #lbl {
  83. color: blue;
  84. cursor: pointer;
  85. }
  86. </style>
  87.  
  88. </head>
  89. <body>
  90.  
  91. <div class="container centered">
  92. <div class="input-group mb-3">
  93. <input id="input" type="text" class="form-control"/>
  94. <div class="input-group-append">
  95. <button type="button" class="btn btn-lg btn-primary" onclick="changeLabel();">
  96. send
  97. </button>
  98. </div>
  99. </div>
  100. <div style="text-align:center;">
  101. A text label (click on it):
  102. <span id="lbl" onclick="getPropertyValue();">some value</span>
  103. </div>
  104. </div>
  105.  
  106. </body>
  107. </html>
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement