Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Emplementing QTouchEvent like to emùulate "native Windows Touch Events"
QtWS25 Last Chance

Emplementing QTouchEvent like to emùulate "native Windows Touch Events"

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 1 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sil20
    wrote on last edited by
    #1

    Hello,
    I would like to emit an QTouchevent like a windows Touch event The idea is to emulate touchpoints for a QML application. So I am not sure:

    • what type of event I shoud send (maybe is is not a QTouchEvent)
    • How I should send it
    • what is the target

    So far I am building a QTouchEvent, I filled the touchpoint list with one point, and post it to the QApplication. But it crashes. In the debugger the callstack become unusable after being in "QtGui4.dll!QGestureEvent::isAccepted()"

    I tried using "QApplication::sendEvent(QApplication::instance(), &event);", it does not crash but the event is not dispatched to the touchAreas.

    I will appreciate some advices. Hereafter is the code I wrote to create and send the event.
    Thancks a lot.

    @ //Create Event structure
    QTouchEvent event(eventType);
    QListQTouchEvent::TouchPoint touchPoints = event.touchPoints();
    QTouchEvent::TouchPoint p;

    //Set Normalized globale position (0;1)
    QPointF lp;
    lp.setX(tcur->getPosition().getX());
    lp.setY(tcur->getPosition().getY());
    
    //Set Touch ID
    int id = tcur->getCursorID();
    
    //Set Values
    p.setNormalizedPos(lp);
    p.setId(id);
    
    //p.setPressure(point->pressure);
    //p.setRect(point->area);
    //p.setScreenPos(point->area.center());
    
    switch (eventType) {
        case QEvent::TouchBegin:
        {
            p.setState(Qt::TouchPointPressed );
            touchPoints.append(p);
            break;
        }
        case QEvent::TouchUpdate:
        {
            p.setState(Qt::TouchPointMoved);
            touchPoints.append(p);
            break;
        }
        case QEvent::TouchEnd:
        {
            p.setState(Qt::TouchPointReleased );
            touchPoints.append(p);
            //touchPoints. Update Existing
            break;
        }
        default:
        {
            break;
        }
    }
    
    //copy data into event structure
    event.setTouchPoints(touchPoints);
    
    //Send Event to main application    
    QApplication::postEvent(QApplication::instance(), &event);
    

    @

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sil20
      wrote on last edited by
      #2

      Hi I FInally get somethingworking but there is still a BUG.
      Here is what I do when I receive TUIO events, in my Application viewer (class ApplicationViewer
      : public QDeclarativeView)

      • I build aQListQTouchEvent::TouchPoint
      • Ifill it with QTouchEvent::TouchPoint
      • I call diredtely:
        @QApplicationPrivate *qAppPriv = QApplicationPrivate::instance();
        qAppPriv->translateRawTouchEvent(this,QTouchEvent::TouchScreen,touchPointsList);@

      on the test QML interface I made using touch areas it start working, but if I move "to much" a touch point (QEvent::TouchUpdate:) or if I touch 2 different touchareas simultaneously I have an

      • [Qt fatal] ASSERT: "cachedItemsUnderMouse.first() == origin" in file graphicsview\qgraphicsscene.cpp, line 5946*

      Does someone has a advice?

      Here is the code where the assertion: occured
      @bool QGraphicsScenePrivate::sendTouchBeginEvent(QGraphicsItem *origin, QTouchEvent *touchEvent)
      {
      Q_Q(QGraphicsScene);

      if (cachedItemsUnderMouse.isEmpty() || cachedItemsUnderMouse.first() != origin) {
          const QTouchEvent::TouchPoint &firstTouchPoint = touchEvent->touchPoints().first();
          cachedItemsUnderMouse = itemsAtPosition(firstTouchPoint.screenPos().toPoint(),
                                                  firstTouchPoint.scenePos(),
                                                  touchEvent->widget());
      }
      Q_ASSERT(cachedItemsUnderMouse.first() == origin);@
      
      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sil20
        wrote on last edited by
        #3

        I found it !

        The problem was:

        • TUIO send SIngle Point Events
        • QT is considering multiple points list events
        • when I build my list I was not changing the point state from Pressed to Stationnary so there was "multiple Pressed event "
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved