Qt-interest Archive, December 2007
QGLWidget inside QScrollBar (newbie problem)
Message 1 in thread
Hello everyone,
I don't have much experience with QT or OpenGL but I have to make a small
program using both of them and perhaps someone here can help me with the
first issue I run into.
I have a QGLWidget that displays a map using the function glDrawPixels(),
this widget is located inside a QScrollArea. Everything works fine until I
zoom in a couple of times, if then I try to scroll down, I get a
segmentation fault. If I debug the program with gdb, then my whole KDE dies.
Here is some code:
The main window:
/****************************************************************/
glMap = new GLMap();
scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Base);
scrollArea->setWidget(glMap);
setCentralWidget(scrollArea);
/****************************************************************/
The GLWidget (GLMap):
/****************************************************************/
void GLMap::initializeGL()
{
glClearColor(255,255,255,255);
glShadeModel(GL_FLAT);
glDisable(GL_DEPTH_TEST);
glPixelZoom( 1.0, 1.0 );
}
void GLMap::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glDrawPixels(mapWidth, mapHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE,
mapBuffer);
}
QSize GLMap::sizeHint() const
{
return QSize(ceil(mapWidth*zoomFactor),ceil(mapHeight*zoomFactor));
}
void GLMap::zoomIn()
{
zoomFactor += 0.1;
adjustSize();
glPixelZoom(zoomFactor,zoomFactor);
updateGL();
}
/****************************************************************/
Can anyone tell me what I'm doing wrong?
Thanks!
Avlaro.
Message 2 in thread
On Dec 11, 2007, at 3:06 PM, Alvaro Aguilera wrote:
> I don't have much experience with QT or OpenGL but I have to make a
> small program using both of them and perhaps someone here can help
> me with the first issue I run into.
>
> I have a QGLWidget that displays a map using the function
> glDrawPixels(), this widget is located inside a QScrollArea.
> Everything works fine until I zoom in a couple of times, if then I
> try to scroll down, I get a segmentation fault. If I debug the
> program with gdb, then my whole KDE dies.
>
> Here is some code:
>
> void GLMap::zoomIn()
> {
> zoomFactor += 0.1;
> adjustSize();
> glPixelZoom(zoomFactor,zoomFactor);
> updateGL();
> }
This is probably not the only problem, but it looks like zoomIn() is
not executing in an OpenGL context. Either call makeCurrent() there,
or postpone your glPixelZoom() call until it gets inside paintGL().
Brad
--
[ signature omitted ]