(Qt for WebAssembly) MultiPointTouchArea loses all touchpoints after just one is released - qt

If I run the following code in the browser using Qt for webassembly I can shift points around, but if one of the two is released, shifting no longer works and this console messages appears:
qt.pointer.dispatch: skipping QEventPoint(id=1 ts=0 pos=0,0 scn=869,370 gbl=869,370 Updated ellipse=(8x8 ∡ 0) vel=0,0 press=-869,-370 last=-869,-370 Δ 869,370) : no target window
import QtQuick
Window {
visible: true
Rectangle {
anchors.fill:parent
MultiPointTouchArea {
anchors.fill: parent
touchPoints: [
TouchPoint {
id: point1
onPressedChanged: console.log('point1', pressed);
},
TouchPoint {
id: point2
onPressedChanged: console.log('point2', pressed);
}
]
}
Rectangle {
width: 200; height: width;
color: "red"
x: point1.x
y: point1.y
}
Rectangle {
width: 200; height: width;
color: "green"
x: point2.x
y: point2.y
}
}
}
I tested it with versions Qt5.15.2, Qt6.4.2, Qt6.5
and different browsers, but the same error occurs all the time.
Link "test it yourself" Online live qml wasm
I debugged a little and it seems the error is in file:
C:\Qt\6.5.0\Src\qtbase\src\gui\kernel\qguiapplication.cpp
Line 2924:
QPointer<QWindow> window = e->window; // the platform hopefully tells us which window received the event
Line 2961:
// If we somehow still don't have a window, we can't deliver this touchpoint. (should never happen)
if (Q_UNLIKELY(!window)) {
qCWarning(lcPtrDispatch) << "skipping" << &tempPt << ": no target window";
continue;
}
here the window is lost.
How can i debug it further?
I also tested it with Qt under Windows, Linux, Android using diffrent versions. There everything works as expected (only using WebAssembly in the browser it doesn't)

If you check the signals of MultiPointTouchArea you see that you get passed a touchPoints array as an argument. This array is valid during the signal handler, and, you need to react accordingly. The following code runs in WebAssembly and you can test it out on a multitouch device:
import QtQuick
import QtQuick.Controls
Page {
background: Rectangle { color: "#848895" }
property list<string> status
MultiPointTouchArea {
anchors.fill: parent
onCanceled: msg(`onCanceled: ${touchPoints.length}`);
onPressed: msg(`onPressed: ${touchPoints.length}`);
onGestureStarted: msg(`onGestureStarted: ${touchPoints.length}`);
onReleased: msg(`onReleased: ${touchPoints.length}`);
onTouchUpdated: msg(`onTouchUpdated: ${touchPoints.length}`);
onUpdated: msg(`onUpdated: ${touchPoints.length}`);
Frame {
anchors.centerIn: parent
background: Rectangle { }
Text {
text: status.join('\n');
}
}
}
function msg(str) {
status.push(str);
if (status.length > 20) status.shift();
}
}
You can Run it WebAssembly now

Related

Error importing "Esri.ArcGISRuntime" to Qt Creator

After running the code an error came:
QQmlApplicationEngine failed to load component
qrc:/main.qml:19:1: module "Esri.ArcGISRuntime" is not installed
I am using Qt Creator 4.11.1 Qt 5.14.1
I am using Ubuntu 20.04
I have already added the path to the LD_LIBRARY_PATH as stated here: https://developers.arcgis.com/qt/install-and-set-up/
I have restarted the Qt Creator and my system but still not working.
Any suggestions?
The code is:
main.qml
import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.ArcGISRuntime 100.14 //error here
Rectangle {
id: rootRectangle
clip: true
width: 800
height: 600
readonly property int initialZoomScale: 8000
property bool trackingEnabled: false
property Point lastPosition: null
// add a mapView component
MapView {
anchors.fill: parent
Map {
Basemap {
initStyle: Enums.BasemapStyleArcGISDarkGray
}
}
// set initial viewpoint near UCLA, Los Angeles
ViewpointCenter {
Point {
x: -13185535.98
y: 4037766.28
}
targetScale: initialZoomScale
}
Button {
id: button
text: trackingEnabled ? "Stop tracking" : "Start tracking"
anchors.horizontalCenter: parent.horizontalCenter
width: 200
onClicked: trackingEnabled =! trackingEnabled
}
SimulationParameters {
id: simulationParameters
velocity: 30
}
locationDisplay {
dataSource: SimulatedLocationDataSource {
id: simulatedLocationDataSource
Component.onCompleted: {
setLocationsWithPolylineAndParameters(polyline, simulationParameters);
simulatedLocationDataSource.start();
}
}
initialZoomScale: initialZoomScale
}
// if tracking is enabled then show location history
locationDisplay.onLocationChanged: {
if (!trackingEnabled)
return;
// clear old route
locationHistoryLineOverlay.graphics.clear();
if (lastPosition !== null) {
polylineBuilder.addPoint(lastPosition);
locationHistoryOverlay.graphics.append(ArcGISRuntimeEnvironment.createObject("Graphic", {geometry: lastPosition}));
}
// update last position
lastPosition = locationDisplay.location.position;
// update the polyline
locationHistoryLineOverlay.graphics.append(ArcGISRuntimeEnvironment.createObject("Graphic", {geometry: polylineBuilder.geometry}));
}
Component.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation
forceActiveFocus();
locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeRecenter;
}
Polyline {
id: polyline
json: {"paths":[[[-13185646.046666779,4037971.5966668758],[-13185586.780000051,4037827.6633333955],
[-13185514.813333312,4037709.1299999417],[-13185569.846666701,4037522.8633330846],
[-13185591.01333339,4037378.9299996048],[-13185629.113333428,4037283.6799995075],
[-13185770.93000024,4037425.4966663187],[-13185821.730000293,4037546.146666442],
[-13185880.996667018,4037704.8966666036],[-13185948.730000421,4037874.2300001099],
[-13185974.130000448,4037946.1966668498],[-13186120.180000596,4037958.896666863],
[-13186264.113334076,4037984.296666889],[-13186336.080000836,4038001.2300002342],
[-13186314.91333415,4037757.8133333195],[-13186272.580000773,4037560.9633331187],
[-13186187.913334005,4037463.59666635],[-13186431.33000092,4037404.3299996229],
[-13186676.863334503,4037290.0299995062],[-13187625.130002158,4038589.6633341513],
[-13187333.030001862,4038756.8800009824],[-13187091.730001617,4038617.1800008402],
[-13186791.163334643,4038805.5633343654],[-13186721.313334571,4038801.3300010278],
[-13186833.49666802,4038195.9633337436],[-13186977.677439401,4037699.8176972247],
[-13186784.921301765,4037820.4541915278],[-13186749.517113185,4038150.8932846226],
[-13186649.860878762,4038288.5762400767],[-13186556.760975549,4038323.9804286221],
[-13186472.839936033,4038481.3323777127],[-13186373.183701571,4038489.1999751539],
[-13186344.335844241,4038242.6819215398],[-13186126.665647998,4038308.245233661],
[-13185814.584282301,4038358.0733508728],[-13185651.987268206,4038116.8003622484],
[-13185203.534213299,4038048.6145176427],[-13184576.748949422,4038150.8932845518],
[-13184251.55492135,4037833.5668537691],[-13184146.653621957,4037524.1080205571],
[-13183949.963685593,4037621.1417224966],[-13183687.71043711,4037781.1162040718],
[-13183480.530370807,4037875.5273735262],[-13182307.629999243,4037859.7460188437],
[-13181376.039484169,4037820.9297473822],[-13180716.162869323,4038364.3575478429],
[-13180182.439136729,4038810.7446696493],[-13178474.523192419,4040237.2426458625],
[-13178321.134040033,4039740.6894803117],[-13177958.020228144,4039140.1550991111],
[-13177073.512224896,4037459.5898928214],[-13177757.842101147,4037589.9384406791],
[-13178386.308314031,4037799.427178307],[-13180095.012208173,4037811.6550856642],
[-13180126.165447287,4036845.9046731163],[-13179806.844746364,4036324.0879179495],
[-13180928.361354485,4035887.9425703473],[-13181598.155995468,4035428.432293402],
[-13182984.47513606,4034447.105261297],[-13182229.264383668,4033222.8051626245],
[-13182058.735615831,4033339.8690072047],[-13181939.035180708,4033691.2477038498],
[-13182116.65518121,4033861.1450956347],[-13181792.305615077,4034085.1007484416],
[-13182027.845180977,4034467.3698799671],[-13181877.254310986,4034644.9898804692],
[-13181630.130832028,4034517.5668366305],[-13181386.868657427,4034424.8955320208],
[-13181228.555178719,4034652.7124891868],[-13181379.14604871,4034942.3103160923],
[-13181267.168222306,4035189.4337950516],[-13181074.103004368,4035015.6750989081],
[-13180807.673003616,4034934.5877073747],[-13180618.469090037,4034814.8872722536],
[-13180599.162568243,4035374.7764042714],[-13181047.073873857,4035494.476839392],
[-13181317.365178969,4035413.3894478586],[-13180765.198655669,4035143.0981427468],
[-13180328.871263131,4034892.1133594285],[-13180270.951697765,4035258.9372735149],
[-13180325.009958787,4035718.4324922049],[-13180707.279090302,4035695.2646660525],
[-13181413.897788007,4035536.9511873648],[-13181618.54691902,4035807.2424924765],
[-13181884.976919774,4036065.949884512],[-13182159.129529245,4035861.3007534989],
[-13182174.57474668,4035668.2355355616],[-13182417.83692128,4035664.374231203],
[-13182784.660835361,4035409.5281435261],[-13182997.032575091,4035255.0759691764],
[-13182618.624747934,4034679.7416197238]]],
"spatialReference":{"latestWkid":3857,"wkid":102100}}
}
GraphicsOverlay {
id: locationHistoryLineOverlay
SimpleRenderer {
SimpleLineSymbol {
color: "lime"
style: Enums.SimpleLineSymbolStyleSolid
width: 2
}
}
}
GraphicsOverlay {
id: locationHistoryOverlay
SimpleRenderer {
SimpleMarkerSymbol {
color: "red"
style: Enums.SimpleMarkerSymbolStyleCircle
size: 3
}
}
}
}
PolylineBuilder {
id: polylineBuilder
spatialReference: SpatialReference { wkid: 3857 }
}
}
I will summarise the issues discussed in the comment thread to bring to an end.
Use Qt 5.15 these days and preferably always the latest bug fix release. Which is currently 5.15.5 for open-source, and not commercial, customers at the time of writing this. Even better to switch to 6.x when possible.
Setting the QML_IMPORT_TRACE environment variable can help debugging these issues.
When using qmake, they seem to suggest including their pri file to your qmake pro file.
Something like a export QML2_IMPORT_PATH=..:$QML2_IMPORT_PATH can also help localising these issues as a quick experiment.

How to recreate Android's Pull to Refresh icon in QML?

This is the pull to refresh icon used to refresh views in Android.
I've been trying to bring that to qml but it is not so easy.
There are so many transitions that it quickly becomes very complex.
How difficult this should be to recreated in QML?
Is using canvas the better solution?
As i have first seen, the swipe brings down the arrow in a different pace of the swipe, while the arrow rotates. If this arrow comes from a canvas how can it relate to outside events, that is the swipe?
I used something like this:
//
// Slot called when the flick has started
//
onFlickStarted: {
refreshFlik = atYBeginning
}
//
// Slot called when the flick has finished
//
onFlickEnded: {
if ( atYBeginning && refreshFlik )
{
refresh()
}
}
It seems to work as expected and it is easy to implement
The problem is that Flickable and the derived ListView don't really provide any over-drag or over-shoot information in the cases where the visual behavior is disabled.
If dragging the visual over the beginning is not a problem for you, you can simply use the negated value of contentY which goes into the negative if the view is dragged before its beginning.
The only solution I can think of to not have any visual over-dragging but still get the over-drag information in order to drive your refresher is to set the view interactive property to false, and put another mouse area on top of that, and redirect drags and flicks manually to the now non-interactive view.
That last part might sound complex, but it isn't that complex, and I happen to know for a fact that it works well, because I have already used this approach and the source code is already here on SO.
So once you have access to the mouse area that controls the view, you can track how much you are in the negative, and use that information to drive the logic and animation of the refresher.
The notable difference between the implementation in the linked answer and what you need is that the linked answer has the mouse area in each delegate, due to the requirements of the specific problem I wanted to solve. You don't need that, you only need one single mouse area that covers the view.
I did like this recently.
Basically I use the position of a ScrollBar and if it goes negative I show a spinner and refresh. So I don't need to mess with the flick stuff.
import QtQuick.Controls 6.0
import QtQuick 6.0
ListView {
ScrollBar.vertical: ScrollBar {
id: scrollbar
}
property bool negativescroll: scrollbar.position < 0
onNegativescrollChanged: {
if (spinner.visible) {
refresh()
}
spinner.visible = !spinner.visible
}
BusyIndicator {
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
visible: false
running: visible
id: spinner
}
width: 180; height: 200
model: model
delegate: Text {
text: name + ": " + number
}
ListModel {
id: model
ListElement {
name: "Bill Smith"
number: "555 3264"
}
ListElement {
name: "John Brown"
number: "555 8426"
}
ListElement {
name: "Sam Wise"
number: "555 0473"
}
}
}
I came to a simpler solution based on dtech's experience involving multiple Flickable elements, which basically consists on filling the Flickable with a MouseArea, setting its boundsBehavior property to Flickable.StopAtBounds, and from there, if it's at the top, do things based on mouseY values.
The better approximation i could get is in the following code. A possible drawback is that diagonal swiping also counts as a refresh intention. It could be improved with GestureArea, but i'm too lazy to get my hands on this at the moment.
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Window 2.2
ApplicationWindow {
property real mm: Screen.pixelDensity
property real margins: 2 * mm
id: mainWindow
visible: true
width: 60 * mm
height: 120 * mm
title: qsTr("Hello World")
ListModel {
id: myModel
Component.onCompleted: {
for(var i = 0; i <= 100; ++i) {
myModel.append({num: i})
}
}
}
ListView {
id: view
boundsBehavior: Flickable.StopAtBounds
interactive: true
anchors.fill: parent
model: myModel
spacing: 4
delegate: Rectangle {
width: parent.width
height: 25 * mm
border.color: 'red'
Text {
id: name
text: num
anchors.centerIn: parent
}
}
Rectangle {
signal follow
id: swatch
width: 15 * mm
height: width
radius: width / 2
color: 'lightgray'
anchors.horizontalCenter: parent.horizontalCenter
y: - height
}
MouseArea {
property int mouseYSart
property int biggerMouseY
anchors.fill: view
onPressed: {
mouseYSart = mouseY
biggerMouseY = 0
}
onMouseYChanged: {
if(view.contentY == 0) {
var currentMouseY = mouseY
if(currentMouseY > biggerMouseY) {
biggerMouseY = currentMouseY
swatch.y += 1
}
if(currentMouseY < biggerMouseY) {
biggerMouseY = currentMouseY
swatch.y -= 1
}
}
}
onReleased: swatch.y = - swatch.height
}
}
}

Open and close additional window (QML)

Currently I have a window openning in the following way:
property variant win
Button {
id: testButton
MouseArea {
onClicked: {
var component = Qt.createComponent("test.qml");
win = component.createObject(testButton);
win.show();
}
}
}
Is it ok to create a window like this or there is a better way to do it (from QML, not from C++)?
When I close this additional window (just by clicking "x" button), I want to connect it to another event (for example, changing color of the button). How to do it?
Thanks.
It is usually nicer to have it more declarative. If you want your button to only open one window, the usage of a Loader might be right for you.
I think this is what you want, as you store it in one variable, and if you click the button multiple times, you would lose access to your instance. If you need a larger amount of Windows created by the same Button, you might use a ListModel and a Instantiator to create the instances.
With the Loader this might look like this:
Button {
id: ldbutton
onClicked: winld.active = true
Rectangle {
id: ldindic
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
}
width: height
color: winld.active ? 'green' : 'red'
}
Loader {
id: winld
active: false
sourceComponent: Window {
width: 100
height: 100
color: 'green'
visible: true
onClosing: winld.active = false
}
}
}
In this code is also already the answer to your second question: The signal you are looking for is called closing - connect to it to do what ever is necessary.
In the case of the Loader it is necessary to unload the window, so it can be loaded again later, maybe. If you have the window created by a Instantiator, you need to remove the corresponding index from the Instantiator's ListModel.
This might look like this:
Button {
id: rpbutton
onClicked: rpmodel.append({})
text: 'Open Windows ' + rpmodel.count
ListModel {
id: rpmodel
}
Instantiator { // from QtQml 2.0
model: rpmodel
delegate: Window {
width: 100
height: 100
color: 'blue'
visible: true
onClosing: rpmodel.remove(index)
}
}
}
In your code you could connect to it, either by using a Connection-object, that connects to your property win, or by changing the JS onClicked like so:
onClicked: {
var component = Qt.createComponent("test.qml");
win = component.createObject(testButton);
win.closing.connect(function() { console.log('do something') })
win.show();
}

BusyIndicator does not show up

I want to show a BusyIndicator while a long process is going on. The problem is it does not show up when I make it run and shows afterwards when the process is completed. According to the docs
The busy indicator should be used to indicate activity while content is being loaded or the UI is blocked waiting for a resource to become available.
I have created a minimal code that based upon the original code
Window {
id: win
width: 300
height: 300
property bool run : false
Rectangle {
anchors.fill: parent
BusyIndicator {
anchors.centerIn: parent
running: run
}
MouseArea {
anchors.fill: parent
onClicked: {
run = true
for(var a=0;a<1000000;a++) { console.log(a) }
run = false
}
}
}
}
So when the Rectangle is clicked I want to display the BusyIndicator for the time till the calculations gets completed.
For example purpose I have used the for loop here. In actual scenario I call a function (which inserts some 1000 rows into the Database) through the ContextProperty. But in that case too the BusyIndicator is not displayed.
Am I doing it the right way? Or what would be the best way to do it?
You cannot view your BusyIndicator just because long operation in onClicked handler blocks application GUI and indicator does not update. You should run such operation in a different thread to avoid freezing of GUI. Simple example:
QML
Window {
id: win
width: 300
height: 300
property bool run : false
Rectangle {
anchors.fill: parent
BusyIndicator {
id: busy
anchors.centerIn: parent
running: win.run
}
MouseArea {
anchors.fill: parent
onClicked: {
win.run = true
thread.sendMessage({run : true});
}
}
WorkerScript {
id: thread
source: "handler.js"
onMessage: {
win.run = messageObject.run;
}
}
}
}
handle.js
WorkerScript.onMessage = function(message) {
if(message.run === true) {
for(var a=0;a<1000000;a++) { console.log(a) }
}
WorkerScript.sendMessage({run : false});
}
There is a way to do this using QQuickWindow's afterSynchronizing signal:
import QtQuick 2.4
import QtQuick.Controls 1.3
ApplicationWindow {
width: 400
height: 400
visible: true
Component.onCompleted: print(Qt.formatDateTime(new Date(), "mm:ss:zzz"), "QML loaded")
onAfterSynchronizing: {
print(Qt.formatDateTime(new Date(), "mm:ss:zzz"), "Window content rendered")
if (!loader.item) {
loader.active = true
}
}
Item {
anchors.fill: parent
BusyIndicator {
running: !loader.item
anchors.centerIn: parent
}
Loader {
id: loader
active: false
anchors.fill: parent
sourceComponent: Text {
wrapMode: Text.Wrap
Component.onCompleted: {
for (var i = 0; i < 500; ++i) {
text += "Hello, ";
}
}
}
}
}
}
The idea is to use a Loader to have control over when the expensive operation happens. You could also use a dynamically loaded component via Qt.createQmlObject(), or Qt.createComponent() to dynamically load a component in a separate file.
If you run the example, you'll see that you get the following output:
qml: 58:12:356 QML loaded
qml: 58:12:608 Window content rendered
We use QQuickWindow's afterSynchronizing signal to know when the content of the window has been displayed, and only act on it the first time (via if (!loader.item)).
When the signal is initially emitted, we can be sure that the BusyIndicator has started its animation, so the user will actually see a spinning icon.
Once the Loader has finished loading the text, its item property will become non-null and the BusyIndicator will disappear.
Run into the same problem today! I will assume you are controlling your BusyIndicator from a C++ property called busy. And you are setting busy to true just before your calculations and to false just after. Doing this solved it for me. It's not a very elegant solution but it works:
QML
BusyIndicator {
running: CPPModule.busy
}
CPP
void CPPModule::setBusy(const bool &busy)
{
m_busy = busy;
emit busyChanged();
}
void CPPModule::InsertIntoDB()
{
setBusy(true);
QThread::msleep(50);
QCoreApplication::processEvents();
/*
very Long Operation
*/
setBusy(false);
}

changing property of element from other qml file

I know that there is tons of topic similar like this, I try to implement answer from them and I still have no results.
I take some sample project from qt creator to play with this. I play with changing visibility of qml files ( treat every file as other screen). After lunching 3rd screen I want to make the second one invisible.
Here Is the code where I want change property in it:
MyLuncherList.qml
import QtQuick 2.0
Rectangle {
Item
{
id:ei
visible:false
clip: true
property url itemUrl
onItemUrlChanged:
{
visible = (itemUrl== '' ? false : true);
}
anchors.fill: parent
anchors.bottomMargin: 40
Rectangle
{
id:bg
anchors.fill: parent
color: "white"
}
MouseArea
{
anchors.fill: parent
enabled: ei.visible
//takes mouse events
}
Loader
{
focus:true
source: ei.itemUrl
anchors.fill: parent
}
}
}
and here is the code where I want to make a action
View2.qml
import QtQuick 2.0
Rectangle {
width: 100
height: 62
Text
{
text: "second screen"
}
MyLuncherList
{
id:luncherList
}
Rectangle
{
x: 50
y: 30
width: 120
height: 60
color: "red"
MouseArea
{
anchors.fill: parent
id: mouseAreaWhichHides
onClicked:
{
luncherList.ei.itemUrl = '';
}
}
}
}
and I got the error: qrc:///View2.qml:29: TypeError: Type error
which point on this line luncherList.ei.itemUrl = '';
Type error says that I make some mismatch with Type, but I’m not even sure, if I do this access process in properly way, so I’m asking how to change property of
ei.itemUrl
from
View2.qml
in working way.
The ei element won't be available directly in other QML file.
You can use an alias to do it.
property alias callUrl: ei.itemUrl
and call it from other QML file
luncherList.callUrl='file:///home/user/file.jpg'

Resources