-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
emscripten_set_mousedown_callback
does not call the callback function from Qt Creator
#22133
Comments
Most likely if you use Qt you probably want to let it handle all the interaction with he mouse etc. Trying to do you own mouse interaction underneath Qt will likely cause confusion or maybe just doesn't work? |
The contributor of Qt said in the comments: https://bugreports.qt.io/browse/QTBUG-126513 that:
I have tried to use it: void mousePressEvent(QMouseEvent *event) override
{
EMSCRIPTEN_RESULT result = emscripten_request_pointerlock(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, false);
qDebug() << result;
} It returns |
I see.. they you need to handle the event directly so that you can request the pointer lock. In that case yes you probably do need to register your own mousedown callback. I'm not sure why shouldn't able to have your one registered alongside the Qt one.. I think they should all fire and we don't use |
How do you think, guys, is it a bug of Qt or Emscripten? https://bugreports.qt.io/browse/QTBUG-126582 |
My guess is that its an emscripten issue, but I'm not sure how this API is supposed to work TBH. Needs more investigation. |
The main goal is to get EM_JS(void, requestPointerLock, (), {
document.body.requestPointerLock();
document.body.onmousemove = (event) => {
console.log(event.movementX, event.movementY);
};
}) And print them here: void mouseMoveEvent(QMouseEvent *event) override
{
Q_UNUSED(event);
// qDebug() << movementX << movementY;
} |
Sorry where are the above code snippets from? is that code from inside of Qt or from your project? I though that goal here was to be able to call |
I try another ways to solve the problem. EM_JS(void, requestPointerLock, (), {
document.body.requestPointerLock();
document.body.onmousemove = (event) => {
console.log(event.movementX, event.movementY);
};
}) void mousePressEvent(QMouseEvent *event) override
{
Q_UNUSED(event);
requestPointerLock();
} It locks the mouse pointer and prints |
I'm not sure that is the right solution.. but if you want to go that route that is certainly questions for Qt. You would need to look at how to create/injext new Qt events, mostly likely take a look at the Qt emscripten implemenation. However, I a little confused because your |
Oh wait.. did you try passing true as the second argument ( |
I tried. The mouse pointer is not locked. It prints -1 to the console when I click. This is the WASM output: dist.zip #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
{
Q_UNUSED(event);
EMSCRIPTEN_RESULT result = emscripten_request_pointerlock(
EMSCRIPTEN_EVENT_TARGET_DOCUMENT, true);
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
|
I don't know but the mouse cursor was locked and the #include <QtGui/QMouseEvent>
#include <QtGui/QOpenGLFunctions>
#include <QtOpenGL/QOpenGLWindow>
#include <QtWidgets/QApplication>
#ifdef Q_OS_WASM
#include <emscripten.h>
#include <emscripten/html5.h>
#endif
#ifdef Q_OS_WASM
EM_JS(void, requestPointerLock, (), {
document.body.requestPointerLock();
document.body.onmousemove = (event) => {
console.log(event.movementX, event.movementY);
};
})
#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
{
Q_UNUSED(event);
requestPointerLock();
}
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
|
Can you step into the code for emscripten_request_pointerlock and see why its returning -1? It should be returning EMSCRIPTEN_RESULT_DEFERRED (1) |
It returns EMSCRIPTEN_RESULT_NOT_SUPPORTED (-1): #define EMSCRIPTEN_RESULT_SUCCESS 0
#define EMSCRIPTEN_RESULT_DEFERRED 1
#define EMSCRIPTEN_RESULT_NOT_SUPPORTED -1 I cannot set a breakpoint at the But I can click on this link: Result: |
You should be able to set a breakpoint in devtools once you have your app running in chrome. You should be able to then step through the |
I have reproduced the problem above in pure Emscripten from CMD: It returns -1 because #include <emscripten.h>
#include <emscripten/html5.h>
#include <iostream>
int main()
{
// Mouse Button Down:
emscripten_set_mousedown_callback(
"#canvas", nullptr, 0, +[](int eventType,
const EmscriptenMouseEvent *e, void *userData) -> EM_BOOL
{
EMSCRIPTEN_RESULT result = emscripten_request_pointerlock(
EMSCRIPTEN_EVENT_TARGET_DOCUMENT, true);
std::cout << result << std::endl;
return EM_FALSE;
});
return 0;
} |
I have replaced main.cpp #include <emscripten.h>
#include <emscripten/html5.h>
#include <iostream>
int main()
{
// Mouse Button Down:
emscripten_set_mousedown_callback(
"#canvas", nullptr, 0, +[](int eventType,
const EmscriptenMouseEvent *e, void *userData) -> EM_BOOL
{
EMSCRIPTEN_RESULT result = emscripten_request_pointerlock("#canvas", true);
std::cout << result << std::endl;
return EM_FALSE;
});
return 0;
} But I cannot reproduce this solution for Qt because when I replace It is because the Qt's canvas doesn't have |
I have tried to replace main.cpp #include <emscripten.h>
#include <emscripten/html5.h>
#include <iostream>
int main()
{
// Mouse Button Down:
emscripten_set_mousedown_callback(
"#canvas", nullptr, 0, +[](int eventType,
const EmscriptenMouseEvent *e, void *userData) -> EM_BOOL
{
EMSCRIPTEN_RESULT result = emscripten_request_pointerlock(
EMSCRIPTEN_EVENT_TARGET_SCREEN, true);
std::cout << result << std::endl;
return EM_FALSE;
});
return 0;
} But why doesn't #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
{
Q_UNUSED(event);
EMSCRIPTEN_RESULT result = emscripten_request_pointerlock(
EMSCRIPTEN_EVENT_TARGET_SCREEN, true);
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();
} |
I have tried main.cpp #include <emscripten.h>
#include <emscripten/html5.h>
#include <iostream>
int main()
{
// Mouse Button Down:
emscripten_set_mousedown_callback(
"#canvas", nullptr, 0, +[](int eventType,
const EmscriptenMouseEvent *e, void *userData) -> EM_BOOL
{
EMSCRIPTEN_RESULT result = emscripten_request_pointerlock(
EMSCRIPTEN_EVENT_TARGET_SCREEN, true);
std::cout << result << std::endl;
return EM_FALSE;
});
return 0;
} |
Another trying. Qt has a div element with id="screen". The 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
{
Q_UNUSED(event);
EMSCRIPTEN_RESULT result = emscripten_request_pointerlock("#screen", true);
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();
} |
I have tried to replace the second argument of 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
{
Q_UNUSED(event);
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();
} |
Here is the EMSCRIPTEN_RESULT result = emscripten_request_pointerlock("#screen", true);
qDebug() << result; The problem is here: var canPerformRequests = JSEvents.canPerformEventHandlerRequests();
and |
Why? Leaving it as |
I have tried both case: |
You said in #22133 (comment) that is returns EMSCRIPTEN_RESULT_DEFERRED.. which would be the correct/working/expected result I think. |
In deferred mode you don't want to be calling Does the differed mode not work for for some reason? |
Locking doesn't work. I click in the client area and see 1 in the console every time when I click. |
I think with the differed mode the actual locking won't happen until the next event. If you click again does the lock take effect? |
BTW, 1 means EMSCRIPTEN_RESULT_DEFERRED mean the locking will occur on the next event.. so that is form of success. |
No: I have uploaded the result build to the free hosting: https://667f439855614296d369a205--small-opengles2-examples-qt6-cpp.netlify.app/ 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
{
Q_UNUSED(event);
EMSCRIPTEN_RESULT result = emscripten_request_pointerlock("#screen", true);
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
|
So the problem here seems to be that the differed action is not working? I guess we need to looking to the call to Can you set a breakpoint in the |
My steps:
|
Sounds like perhaps a bug in the differed call mechanism. I'm not very familiar with that or if/how it gets tested I'm afraid. |
The next example works without problems when I compile and run it from the command line:
emcc -g main.cpp -o public/index.html
But when I createEmpty qmake Project
from Qt Creater and run it - it doesn't work - it does not print "Mouse down" to the console:main.cpp
I create a project in Qt Creator like this:
The text was updated successfully, but these errors were encountered: