Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. emscripten_request_pointerlock() returns EMSCRIPTEN_RESULT_UNKNOWN_TARGET
Forum Updated to NodeBB v4.3 + New Features

emscripten_request_pointerlock() returns EMSCRIPTEN_RESULT_UNKNOWN_TARGET

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
5 Posts 1 Posters 545 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.
  • 8 Offline
    8 Offline
    8Observer8
    wrote on 19 Jun 2024, 10:41 last edited by 8Observer8
    #1

    I have made an example that calls emscripten_request_pointerlock("screen", false); by mouse click:

    void mousePressEvent(QMouseEvent *event) override
    {
        EMSCRIPTEN_RESULT result = emscripten_request_pointerlock("screen", false);
        qDebug() << result;
    }
    

    It prints -4 to the console that means EMSCRIPTEN_RESULT_UNKNOWN_TARGET.

    main.cpp

    #include <QtGui/QMouseEvent>
    #include <QtGui/QOpenGLFunctions>
    #include <QtOpenGL/QOpenGLWindow>
    #include <QtWidgets/QApplication>
    
    #ifdef Q_OS_WASM
    #include <emscripten.h>
    #include <emscripten/html5.h>
    #endif
    
    class OpenGLWindow : public QOpenGLWindow, private QOpenGLFunctions
    {
    
    public:
    
        OpenGLWindow()
        {
            setTitle("OpenGL ES 2.0, Qt6, C++");
            resize(350, 350);
        }
    
    private:
    
        void mousePressEvent(QMouseEvent *event) override
        {
            EMSCRIPTEN_RESULT result = emscripten_request_pointerlock("screen", false);
            qDebug() << result;
        }
    
        virtual void initializeGL() override
        {
            initializeOpenGLFunctions();
            glClearColor(0.2f, 0.2f, 0.2f, 1.f);
        }
    
        virtual void paintGL() override
        {
            glClear(GL_COLOR_BUFFER_BIT);
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL);
        QApplication app(argc, argv);
        OpenGLWindow w;
        w.show();
        return app.exec();
    }
    

    pro

    QT += core gui openglwidgets
    
    win32: LIBS += -lopengl32
    
    CONFIG += c++17
    
    wasm: INCLUDEPATH += "C:\emsdk\upstream\emscripten\cache\sysroot\include"
    
    SOURCES += \
        main.cpp
    
    1 Reply Last reply
    0
    • 8 Offline
      8 Offline
      8Observer8
      wrote on 21 Jun 2024, 16:38 last edited by
      #5

      The bug report was closed because You need to handle this in a javascript mouse event and not a Qt mouse event. I will continue here: https://forum.qt.io/topic/157373/emscripten_set_mousedown_callback-does-not-call-the-callback-function

      1 Reply Last reply
      0
      • 8 Offline
        8 Offline
        8Observer8
        wrote on 19 Jun 2024, 11:51 last edited by 8Observer8
        #2

        I use screen above because the Qt's html file has this element: <div id="screen"></div> I have tried to use EMSCRIPTEN_EVENT_TARGET_DOCUMENT instead of screen but it returns -1 (it means EMSCRIPTEN_RESULT_NOT_SUPPORTED)

        EMSCRIPTEN_RESULT result = emscripten_request_pointerlock(
                    EMSCRIPTEN_EVENT_TARGET_DOCUMENT, false);
        qDebug() << result;
        
        1 Reply Last reply
        0
        • 8 8Observer8 referenced this topic on 19 Jun 2024, 23:21
        • 8 Offline
          8 Offline
          8Observer8
          wrote on 19 Jun 2024, 23:23 last edited by
          #3

          I have created the bug report: https://bugreports.qt.io/browse/QTBUG-126513

          1 Reply Last reply
          0
          • 8 Offline
            8 Offline
            8Observer8
            wrote on 21 Jun 2024, 12:04 last edited by 8Observer8
            #4

            Why cannot I set a mouse down callback from Qt's constructor? It prints nothing when I click:

            EM_BOOL mouse_down_callback(int eventType, const EmscriptenMouseEvent *event,
                void *userData)
            {
                qDebug() << event->screenX << event->screenY;
                return 0;
            }
            
            class OpenGLWindow : public QOpenGLWindow, private QOpenGLFunctions
            {
            public:
                OpenGLWindow()
                {
                    setTitle("OpenGL ES 2.0, Qt6, C++");
                    resize(350, 350);
                    emscripten_set_mousedown_callback(
                        EMSCRIPTEN_EVENT_TARGET_WINDOW,
                        NULL,
                        1,
                        mouse_down_callback
                    );
                }
            
            1 Reply Last reply
            0
            • 8 Offline
              8 Offline
              8Observer8
              wrote on 21 Jun 2024, 16:38 last edited by
              #5

              The bug report was closed because You need to handle this in a javascript mouse event and not a Qt mouse event. I will continue here: https://forum.qt.io/topic/157373/emscripten_set_mousedown_callback-does-not-call-the-callback-function

              1 Reply Last reply
              0
              • 8 8Observer8 has marked this topic as solved on 21 Jun 2024, 16:39

              1/5

              19 Jun 2024, 10:41

              • Login

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