Important: Please read the Qt Code of Conduct -

[Solved] QtGui 5.0: OpenGL Window Example - Black screen on Mac

  • Hi all,

    I have just started to experiment with Qt 5.0 and OpenGL on Mac OS X and Windows using the "QtGui 5.0: OpenGL Window Example tutorial.": While the example builds on both platforms smoothly, it only runs correctly under Windows. The Mac version shows the window but does not render any output. Debugging shows that events are processed as expected. Has anyone experienced the same issues?

    I could locate the reason for the problem. The screen refresh rate is reported as zero (line 14 - screen()->refreshRate()), which breaks the rotation matrix calculation:
    @void TriangleWindow::render()
    glViewport(0, 0, width(), height());

    QMatrix4x4 matrix;
    matrix.perspective(60, 4.0/3.0, 0.1, 100.0);
    matrix.translate(0, 0, -2);
    matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0);


    Setting the refresh rate to a const value of 60 makes the example work. I will investigate further in the behavior of QScreen on the Mac platform.


  • Yes, same issue for me on a MacBook Pro 2.66 GHz Core i7 with a GeForce GT 330M running 10.8.2. Your suggested modification fixed the problem.

Log in to reply