Qt 应用程序可以在台式机上运行,但不能在笔记本电脑上运行?
我正在使用 Qt 编写一个 OpenGL 应用程序,它在我的桌面上构建并运行良好,但是当我尝试在我的笔记本电脑上运行完全相同的代码时,它构建但不输出任何内容?这是我的 main.cpp
#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include "GLWidget.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
GLWidget window;
window.resize(1050,700);
window.setFixedSize(1050, 700);
window.show();
return app.exec();
}
我不希望用户能够调整窗口大小,因此固定大小。如果我在 main 的最后一行设置断点,它永远不会在我的笔记本电脑上到达它。我已经单步执行了代码,在调用 show() (这只是一个内联函数)之后,调试器以代码 0 结束。我检查了所有项目构建和运行设置,它们在两台机器上都是相同的。 我的台式机有一个 1920x1080 的显示器,但我的笔记本电脑只有 1366x768 这可能有什么关系吗? Qt 中是否有某种取决于我的屏幕分辨率的内部检查?这几乎是我能想到的唯一的事情。
I am writing an OpenGL app using Qt, and it builds and runs fine on my desktop, but when I try running the exact same code on my laptop, it builds but does not output anything? Here is my main.cpp
#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include "GLWidget.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
GLWidget window;
window.resize(1050,700);
window.setFixedSize(1050, 700);
window.show();
return app.exec();
}
I do not want the user to be able to resize the window, hence the fixed size. If I set a breakpoint on the last line of main, it never reaches it on my laptop. I have stepped through the code and right after show() is called (which is just an inline function) the debugger finishes with code 0. I checked all the project build and run settings, they are the same on both machines.
My desktop has a 1920x1080 monitor, but my laptop is only 1366x768 could this have anything to do with it? Is there some sort of internal check going on under the hood in Qt that depends on my screens resolution? That is pretty much the only thing I can think of.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大小请问为什么?我可以假设您希望窗口具有固定大小,因为您想使用 OpenGL 生成恰好这个大小的图像吗?如果是这样,那么我必须告诉你,那样是行不通的。 OpenGL 实现只会渲染屏幕上可见的内容(像素所有权测试)。如果窗口的某些部分不可见(在您的情况下,笔记本电脑上就是这种情况),那么这些像素就不会被渲染。读出帧缓冲区将使这些像素未定义。
解决此问题的正确方法是使用 PBuffer 或帧缓冲区对象 (FBO)。 FBO 更易于使用,但在 Windows 上的支持并不广泛(Windows 上的英特尔显卡对 FBO 的支持相当差)。所有 Linux OpenGL 实现(Mesa(也支持 Intel)、ATI/AMD 和 NVidia)均支持 FBO。网络上有许多 FBO 和 PBuffer 教程。
May I ask why? May I presume you want the window to be a fixed size, because you want to use OpenGL to generate a image exactly this size? If so, then I must tell you, it will not work that way. OpenGL implementations will only render what will become visible on the screen (pixel ownership test). If parts of the window are not visible (and in your case this will be the case on the laptop) those pixels are simply not rendered. Reading out the framebuffer will leave those pixels undefined.
The proper way to tackle this problem is using either a PBuffer, or a Frame Buffer Object (FBO). FBOs are easier to use, but not as widely supported on Windows (Intel graphics on Windows have rather poor FBO support). FBOs are supported by all Linux OpenGL implementations (Mesa (also does Intel), ATI/AMD and NVidia). There are numerours FBO and PBuffer tutorials in the web.