<style type="text/css"> <!-- @page {margin:2cm} pre {font-family:"DejaVu Sans Mono",monospace} p {margin-bottom:0.21cm} strong {font-style:italic; font-weight:normal} --> </style>
修改VowelCube例子使其正确地显示
大名鼎鼎的Qt教程《C++GUI Programming with Qt 4, secondedition》源代码出现了错误。VowelCube例子在我的计算机(Ubuntu和Windows8)无法运行。Ubuntu下无法显示三维图形,Windows8显示出现错误而崩溃。
后来查看了相关的论坛,我了解了怎样修改这个例子使其顺利地运行。资源下载地址:这里
首先在构造函数中添加以下的代码,不填充背景和不自动进行缓存交换。
setAutoBufferSwap( false ); setAutoFillBackground( false );
然后在重写的paintEvent()函数中添加下面的代码:
QPainter painter( this ); drawBackground( &painter ); painter.end( ); drawCube( ); painter.begin(this); drawLegend(&painter); painter.end( ); swapBuffers( );
编译,即可运行。


本文详细介绍了如何解决在Ubuntu和Windows8上运行VowelCube例子时遇到的问题。通过在构造函数中设置`setAutoBufferSwap(false);`和`setAutoFillBackground(false);`,并重写`paintEvent()`函数添加特定代码,可以使得该例子顺利运行。
3104

被折叠的 条评论
为什么被折叠?



