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. Touch input not accepted in Windows 8 if QtQuick2ApplicationViewer is subclassed
Forum Updated to NodeBB v4.3 + New Features

Touch input not accepted in Windows 8 if QtQuick2ApplicationViewer is subclassed

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.3k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jech
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      }@

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jech
        wrote on last edited by
        #3

        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.

        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