[Interest] The touch screen events are block after deleteLater function

Axel Spoerl axel.spoerl at qt.io
Thu Feb 16 13:09:12 CET 2023


Hi Gianmarco,

if I understand the code correctly, you depend on signals being fired from a push button. The Home class doesn't look like a button, so it will never receive mouse button events.
That's probably why the qDebug() doesn't see any.

You need to intercept the events of that push button:
Unless already enabled, please set the Qt::WA_AcceptTouchEvents attribute on the button. Install an event filter on the button and qDebug() all incoming events.
Watch out for TouchBegin, TouchUpdate, TouchEnd. You could intercept and interpret those and emit an own signal, if the press & release signals don't get fired correctly.

Brgds
Axel
________________________________
Von: g.scarpelli at u-tech.it <g.scarpelli at u-tech.it>
Gesendet: Donnerstag, 16. Februar 2023 12:41
An: Axel Spoerl <axel.spoerl at qt.io>
Cc: interest at qt-project.org <interest at qt-project.org>
Betreff: Re:AW: [Interest] The touch screen events are block after deleteLater function


Hi Axel ,

Using the qDebug I see and the code below, QEvent::MouseButtonPress never fires if I press the touch:

----------Home.cpp-------------

bool Home::event ( QEvent * curEvent ) {

      if ( curEvent -> type ( ) == QEvent::MouseButtonPress ) {
              qDebug ( ) << "Click!"  ;
     }

     return QWidget::event ( curEvent ) ;
}


------------Home.h--------------
...
private:
      bool event ( QEvent * curEvent ) override ;
...

I also tried using the setFocus and update function. But I don't solve the problem. In this way:


void Home::closeAvvioLavaggio()
{
     disconnect(window,&Lavaggio::closeLavaggio,this,&Home::closeAvvioLavaggio);
     window->deleteLater();
     window = nullptr ;

    this->setFocus ( ) ;
   this->update ( ) ;


}

do you have any suggestion?

Thanks,

Gianmarco

[http://www.marketingaziende.it/sites/default/files/aziende/foto/microtechsrl_1486503464_F.png]


*-*-*-*-*-*-*-*-*-*-*-*-*
Dot. Gianmarco Scarpelli
Microtech Srl
Via Mameli, 94
53043 Chiusi (Si)
http://www.microtechsrl.net
Tel +39 0578 294621
Fax +39 0578 1900218
************************
Attenzione: Le informazioni contenute in questo messaggio di posta elettronica sono private e confidenziali, riservate solo all'attenzione del destinatario. Qualora doveste ricevere questo messaggio per errore, Vi notifichiamo con la presente che ogni diffusione, riproduzione, distribuzione o utilizzo del presente messaggio è altamente proibita. Siete pregati di informare il mittente con un messaggio di risposta e cancellare immediatamente il presente messaggio ed il suo eventuale contenuto, senza copiarlo o aprirlo.
*****************************************************
This e-mail and any file transmitted with it, which may contain confidential and/or privileged material, is legally privileged and intended solely for the recipient. Access to this e-mail by anyone else, use it for any purpose, store, copy, disclose the contents to any other person totally or partially is strictly prohibited and illegal. If you are not the intended recipient(s), please do not read this e-mail, delete this message and any attachments from your system and contact the sender by reply e-mail or by telephone.
*****************************************************


>From "Axel Spoerl" axel.spoerl at qt.io
To "interest at qt-project.org" interest at qt-project.org,"g.scarpelli at u-tech.it" g.scarpelli at u-tech.it
Cc
Date Thu, 16 Feb 2023 10:39:35 +0000
Subject AW: [Interest] The touch screen events are block after deleteLater function

It's difficult to analyze the problem without seeing the whole code, especially the graphics layout.
The deleteLater-instruction will cause the object to be deleted, when events are being processed.
The error could be another widget acquiring focus or overlaying the button, before the button is released.
When the finger is released, the touch gesture can no longer be attributed to the button and the release signal is not emitted.
That would explain why it happens on the touch screen, but not with the mouse.
A possible workaround is to connect to the button's pressed signal.

In order to find the issue, you have to implement a helper, listening to all relevant signals and qDebug() the result.
The screen freeze could be caused by accessing a deleted object, but also by a blocking infinite loop. Throwing qDebugs in the code will shed more light on this.
________________________________
Von: Interest <interest-bounces at qt-project.org> im Auftrag von g.scarpelli at u-tech.it <g.scarpelli at u-tech.it>
Gesendet: Donnerstag, 16. Februar 2023 10:53
An: interest at qt-project.org <interest at qt-project.org>
Betreff: [Interest] The touch screen events are block after deleteLater function


Hi,

I am development my application with the qt 5.15 (c++ code) .The my application is implement using objects are child of the QWidget class. Every time that I open a child class connect the closing signal at the slot to parent class to delete the object child :

PARENT CLASS :
windows = new ChildClass ( ) ;
connect (childClass,&childClass::signalClose,parentClass,&parentClass::closeChildClass);
windows-> showFullScreen ( ) ;

CHILD CLASS :
emit signalClose ( ) ;

PARENT CLASS :
slot closeChildClass :
windows-> deleteLater ( ) ;

I have Implement a application to execute this simple code, if I can keep press the touch screen with my finger when the application execute the windows-> deleteLater ( ) instruction, the touch screen is freeze, I don't can to press the button of the my application with the display touch. While if I connect the mouse I can press the button correctly, but if to press button with the finger not spring the &QPushButton::released event. If I can to active &QPushButton::released event with mouse, means that my application is not block and the button is enabled. If I comment the windows-> deleteLater ( ) instruction I don't this problem. Afer that problem occurred if I restart the application it work correctly, without power off the pc, so the display touch work correcty.

Can you help me ?
This problem blocking the release the my application !
Thanks

----------------------- home.h -------------------------`

#ifndef HOME_H
#define HOME_H

#include <QWidget>


//---------------------
//INCLUDE VALIDI PER TUTTE LE FINESTRE
#include <QScreen>
#include <QDebug>
#include <QTimer>
#include <QDateTime>
#include <QFile>
#include <QJsonDocument>
#include <QJsonValue>
#include <QJsonArray>
#include <QJsonObject>
#include <QFileInfo>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QMessageLogContext>
#include <QLoggingCategory>
//---------------------
#include "lavaggio.h"

#include <QtGui>
#include <QPainter>
#include <QStyleOption>
#include <QDir>


namespace Ui {
class Home;
}

class Home : public QWidget
{
    Q_OBJECT

public:
    explicit Home ( Init *tmp_init = nullptr, QWidget *parent = nullptr ) ;
    ~Home();

 protected:
    void paintEvent(QPaintEvent *)
    {
        QStyleOption opt;
        opt.init(this);
        QPainter p(this);
        style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    }

signals :

public slots :

   void openAvvioLavaggio();
   void closeAvvioLavaggio();

private slots:

private :
    Ui::Home *ui ;
    Lavaggio *window = nullptr ;

} ;


#endif // HOME_H

----------------------- home.cpp -------------------------
Home::Home (Init * tmp_init , QWidget * parent ) :
    QWidget ( parent ) ,
    ui ( new Ui::Home )
{
    qDebug ( ) << "Load Home" ;

    ui->setupUi(this);

    this -> setWindowFlags ( Qt::Window | Qt::CustomizeWindowHint ) ;
connect(ui->btn_avvio_lavaggio, &QPushButton::released, this, &Home::openAvvioLavaggio);

}

void Home::openAvvioLavaggio(){

    qDebug ( ) <<"Start 'wash'.";

    // creo istanza oggetto finestra Avvio Lavaggio
    window= new Lavaggio();

    //collego slot-signal all'eventi di chiusura del widget
    // Note : time to execute this instruction about 500ms
    connect(window,&Lavaggio::closeLavaggio,this,&Home::closeAvvioLavaggio);

    //visualizzo schermata Avvio Lavaggio
    window->showFullScreen();

    // Remove the 'stays on top hint'
    this -> setWindowFlags ( Qt::Window | Qt::CustomizeWindowHint ) ;


}

void Home::closeAvvioLavaggio()
{
    qDebug ( ) <<"closeAvvioLavaggio";

    //scollego slot-signal all'eventi di chiusura del widget
    disconnect(window,&Lavaggio::closeLavaggio,this,&Home::closeAvvioLavaggio);
    window->deleteLater();
    window = nullptr ;

}

----------------------- lavaggio.h -------------------------
#ifndef LAVAGGIO_H
#define LAVAGGIO_H

#include <QWidget>
//---------------------
//INCLUDE VALIDI PER TUTTE LE FINESTRE
#include <QScreen>
#include <QDebug>
#include <QTimer>

#include <QDateTime>
#include <QProcess>
#include <QFile>
#include <QJsonDocument>
#include <QJsonValue>
#include <QJsonArray>
#include <QJsonObject>
#include <QFileInfo>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QSqlRecord>

#include <QtGui>
#include <QPainter>
#include <QStyleOption>

//---------------------
#include "pagamentolavaggioasciugatura.h"
#include "messagebox.h"
#include "ChooseTypeWash.h"
#include "laundrysettings.h"
#include "laundryapp.h"


namespace Ui {
class Lavaggio;
}

class Lavaggio : public QWidget
{
    Q_OBJECT

public:
    explicit Lavaggio( QWidget *parent = nullptr);
    ~Lavaggio();


protected:
    void paintEvent(QPaintEvent *)
    {
        QStyleOption opt;
        opt.init(this);
        QPainter p(this);
        style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    }

signals :
    // Close the window
    void closeLavaggio ( ) ;

private slots:
    // Exit from screen
    void exitWash ( ) ;

private:
    Ui::Lavaggio *ui;

} ;

#endif // LAVAGGIO_H


----------------------- lavaggio.cpp -------------------------

Lavaggio::Lavaggio ( QWidget *parent ) :
    QWidget(parent),
    ui(new Ui::Lavaggio)
{
    qDebug ( ) <<"Load Lavaggio";

    //--------------------------------------
    //CARICAMENTO GRAFICA
    //avvio caricamento grafica
    ui->setupUi(this);

    // --------------------------------------
    // PERSONALIZZAZIONE GRAFICA
    // queste impostazioni grafiche devono valere per tutte le finestre
    // per eliminare la toolbar
    // Note: Time to execute this instruction about 500ms
    this->setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint );

    connect(ui->btn_indietro, &QPushButton::released, this, &Lavaggio::exitWash);

}

void Lavaggio::exitWash ( ) {

    qDebug ( ) <<"Check Exit wash" ;

        qDebug ( ) << "Exit -> wash" ;

        emit closeLavaggio ( ) ;

        close ( ) ;

}






[http://www.marketingaziende.it/sites/default/files/aziende/foto/microtechsrl_1486503464_F.png]


*-*-*-*-*-*-*-*-*-*-*-*-*
Dot. Gianmarco Scarpelli
Microtech Srl
Via Mameli, 94
53043 Chiusi (Si)
http://www.microtechsrl.net
Tel +39 0578 294621
Fax +39 0578 1900218
************************
Attenzione: Le informazioni contenute in questo messaggio di posta elettronica sono private e confidenziali, riservate solo all'attenzione del destinatario. Qualora doveste ricevere questo messaggio per errore, Vi notifichiamo con la presente che ogni diffusione, riproduzione, distribuzione o utilizzo del presente messaggio è altamente proibita. Siete pregati di informare il mittente con un messaggio di risposta e cancellare immediatamente il presente messaggio ed il suo eventuale contenuto, senza copiarlo o aprirlo.
*****************************************************
This e-mail and any file transmitted with it, which may contain confidential and/or privileged material, is legally privileged and intended solely for the recipient. Access to this e-mail by anyone else, use it for any purpose, store, copy, disclose the contents to any other person totally or partially is strictly prohibited and illegal. If you are not the intended recipient(s), please do not read this e-mail, delete this message and any attachments from your system and contact the sender by reply e-mail or by telephone.
*****************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20230216/93e3ca85/attachment.htm>


More information about the Interest mailing list