我正在 Qt Creator 中编写一个项目,如果我编写
QPoint cursorPos=QCursor::pos();
然后cursorPos={-2147483648,-2147483648}这显然是错误的。但是,如果我写
QApplication *application=new QApplication(argc,argv);
QPoint cursorPos=QCursor::pos();
那么cursorPos就是正确的鼠标位置。有什么方法可以让 QCursor::pos() 在没有 QApplication 的情况下工作吗?谢谢。 :D
最佳答案
QApplication
对象做了很多初始化工作。 Qt 文档中 QApplication
的主要职责领域之一:
It manages the application's mouse cursor handling, see setOverrideCursor()
还来自有关 QCursor
的 Qt 文档:
Note: It is possible to create a QCursor before QGuiApplication, but it is not useful except as a place-holder for a real QCursor created after QGuiApplication. Attempting to use a QCursor that was created before QGuiApplication will result in a crash.
因此,在没有 QApplication
或 QGuiApplication
的情况下,似乎无法使用 QCursor
。
关于c++ - 如何在不使用 QApplication 的情况下使用 QCursor::pos() ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24582682/