简体   繁体   中英

Qt-App on Windows Boot: Touchscreen generates mouse move to but no click

We have a Qt GUI application being started on boot through registry Run/RunOnce-Key.

When started on boot the Qt application gets position from touch screen but does not get the click event (emulated mouse click on button) itself.

When run manually the Qt application gets position and click from touch screen.

When using the mouse both version work fine. Other applications started on boot do accept the click through touch.

We do not have any TouchEvents implemented, the touchscreen is just interpreted as mouse events. I guess the application is just to quick and starts before the touchscreen driver being completly loaded and somehow bugs the "click" event then. But i don't know how to validate this or how to look for the problem at all.

We run different systems where this problem does not occur, its just this one windows pc we have the trouble with now. Changing the pc is an option for removing the problem, but i still want to find the source of the problem to make sure this won't happen again. Currently its one out of 100 systems having this problem.

I wrote a small additional application installing an eventFilter to qApp to see what events actually arrive. When run on boot i only receive mouse-move events, while started manually later i receive move press release events.

I wonder if someone else has encountered similar touch problems with Qt/"clickapplications" and touchscreens itself.

bool MouseFilter::eventFilter(QObject *o, QEvent *e)
{
    if(e->type() == QEvent::MouseMove)
    {
        emit signalMouseMove();
        return true;
    }else if(e->type() == QEvent::MouseButtonRelease) {
        emit signalMouseRelease();
        return true;
    }else if(e->type() == QEvent::MouseButtonPress) {
        emit signalMousePress();
        return true;
    }else if(e->type() == QEvent::MouseButtonDblClick) {
        emit signalMouseDoubleClick();
        return true;
    }
    return QObject::eventFilter(o,e);
}

MouseFilter *mf = new MouseFilter();
qApp->installEventFilter(mf);

Problem "solved" by (workaround) adding a sleep timer before QApplication call. The problem seems to be connected to the super fast boot using SSD and autostart using registry Run-key while touchscreen drivers still seem to be loading.

Important: The sleep call has to be made before QApplication is created, otherwise you just keep having the problem.

int main(int argc, char *argv[])
{
    QThread::sleep(15);

    QApplication a(argc, argv);

    if(!QDir::setCurrent(QApplication::applicationDirPath()))
            QDir::setCurrent("C:\\ApplicationPath\\");

    Translator *t = new Translator();
    a.installEventFilter(t);

    return a.exec();
}

Qt Support recommends the to check for GetSystemMetrics(QT_SM_DIGITIZER) using windows native functions. I extended this a bit to have a nice Splash Screen so user has a notification something is happening:

static inline bool hasTouchSupport(QSysInfo::WinVersion wv)
{
    enum { QT_SM_DIGITIZER = 94, QT_NID_INTEGRATED_TOUCH = 0x1,
           QT_NID_EXTERNAL_TOUCH = 0x02, QT_NID_MULTI_INPUT = 0x40 };

    return wv < QSysInfo::WV_WINDOWS7 ? false :
        (GetSystemMetrics(QT_SM_DIGITIZER) & (QT_NID_INTEGRATED_TOUCH | QT_NID_EXTERNAL_TOUCH | QT_NID_MULTI_INPUT)) != 0;
}

int main(int argc, char *argv[])
{


    if(!hasTouchSupport(QSysInfo::windowsVersion())) {
        QApplication *ta = new QApplication(argc,argv);

        QPixmap logo("C:\\PathToLogo\\LogoTransparent.png");
        QSplashScreen splash(logo);
        splash.show();
        clock_t start = clock();
        while(30*CLOCKS_PER_SEC > clock()-start)
        {
            if(hasTouchSupport(QSysInfo::windowsVersion()))
                break;
            ta->processEvents();
            QThread::msleep(20);
        }
        splash.close();
        ta->quit();
        ta->processEvents();
        delete ta;
    }

    QApplication *a = new QApplication(argc, argv);
    //Custom Code goes here

    return a->exec();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM