Touch input not accepted in Windows 8 if QtQuick2ApplicationViewer is subclassed



  • Hi,

    I wrote a QML/C++ program. Now I purchased a Windows 8.1 tablet and if I run the application, it won't respond to any touch o gesture. I found out that the problem is caused by a small portion of code in which I subclassed QtQuick2ApplicationViewer. The code looks like this:

    @class Window : public QtQuick2ApplicationViewer
    {
    QmltoCpp* qmltocpp;

    public:
    void setQmlClass(QmltoCpp* &qmlClass) {
    qmltocpp = qmlClass;
    }

    protected:
    bool event(QEvent *e) Q_DECL_OVERRIDE
    {
    int type = e->type();
    if (type == QEvent::Close) {
    qmltocpp->exit();
    }
    return QWindow::event(e);
    }
    };

    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);
    Window viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/MyApp/main.qml"));
    viewer.showExpanded();
    return app.exec();
    }
    @

    I subclassed the QtQuick2ApplicationViewer to be able to catch application close event and save settings to a database.

    If I just replace the line
    @Window viewer;@
    by
    @QtQuick2ApplicationViewer viewer;@
    it works as expected except my settings are not saved of course.

    Is there anything wrong in my code which would explain this behavior? Is there any other way how I can catch and delay application exit?


  • Lifetime Qt Champion

    Hi,

    @
    bool event(QEvent *e) Q_DECL_OVERRIDE
    {
    int type = e->type();
    if (type == QEvent::Close) {
    qmltocpp->exit();
    }
    return QWindow::event(e); << it's not the base class implementation
    }@



  • Hi,
    thanks a lot for the tip.

    I found the code I'm using here: http://answer.techwikihow.com/297416/ask-confirmation-before-closing-qquickview-qapplication.html

    I now tried another approach and installed an eventFilter which filters QEvent::Close. The code now looks like this:

    @class Window : public QtQuick2ApplicationViewer
    {
    QmltoCpp* qmltocpp;

    public:
    void setQmlClass(QmltoCpp* &qmlClass) {
    qmltocpp = qmlClass;
    }

    protected:
    bool eventFilter(QObject *obj, QEvent *ev) {
    if (ev->type() == QEvent::Close) {
    qmltocpp->exit();
    return true;
    } else {
    return false;
    }
    }
    };

    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);
    Window viewer;
    viewer.installEventFilter(&viewer);
    viewer.setMainQmlFile(QStringLiteral("qml/MyApp/main.qml"));
    viewer.showExpanded();
    return app.exec();
    }
    @

    The function qmltocpp->exit() writes the settings to database and then closes the app by calling
    @QGuiApplication::quit();@

    It works as before on Windows 7, tomorrow I'll try it on my Windows 8 tablet. I hope it will work now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.