3

So I've run into a problem while integrating QT and OSG. I've had a QT/OSG program that been working just fine. The layout is simlar to what you see below.

|--------------------------|
|  1   |         2         |
|      |                   |
|      |                   |
|      |                   |
|      |                   |
|      |                   |
|      |-------------------|
|      |         3         |
|      |                   |
|--------------------------|

The central widget consists of a QFrame which has three sub widgets and is using grid layout. Widget 1 is a QFrame also with a grid layout. Widget 2 is the OSG viewer as described below. Widget 3 is a QFrame also with a grid layout.

Two is populated with a widget modeled after the example in osgviewerQT.cpp. Basically it uses an embedded window and I have a QTimer that fires every 10 milliseconds and calls the osg frame function.

I have 4 other widgets. Two QLabels and two QTables which I populate dynamically. I've been adding all four of these widgets to 1's grid layout. When I do that everything works nicely and I get my nice scene graph in 2. If I make one change, moving these four widgets from 1 to 2's grid layout suddenly my scene graph disappears. Any ideas what is going wrong? I've checked in valgrind so I am pretty sure its not a memory issue and rather its how I am using the lib. I've confirmed the frame function is being called.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
David Mokon Bond
  • 1,576
  • 2
  • 18
  • 42
  • Without any code to see, it's rather hard to hard to tell. – Clare Macrae May 12 '12 at 07:16
  • Which areas of code would be most helpful to see. Its a lot of code... – David Mokon Bond May 12 '12 at 12:35
  • 1
    Sometimes stripping code out to create a minimal example to show the problem actually helps solve the problem. – Clare Macrae May 12 '12 at 15:23
  • Please see the following stripped application that demonstrates the problem. http://mokon.net/ex/ Notice in GUI.cpp I have the #if 1 ... toggle the 1 to 0 and you will see the scene graph appear. – David Mokon Bond May 13 '12 at 04:20
  • I don't think your scene graph disappears. It shows or doesn't show its content. But the widget is still where it has to be. So I don't think it's a layout problem but a problem how you use the scene graph. – leemes May 20 '12 at 13:58
  • That could very well be true but given that source code about (mokon.net/ex) do you see what the problem is? In this example I just load a single model onto the scene graph. – David Mokon Bond May 20 '12 at 19:50
  • Hi, I'm also trying to do what you have achieved. Just one question: do you have signals/slots in your app? For example, if I try to connect a signal from Widget #1 with a slot from Widget #3, at runtime I get an error: `QWidget: Must construct a QApplication before a QPaintDevice*`. Did something like this happen to you? – Adri C.S. Mar 12 '13 at 14:22
  • I use signals all over my application. That error sounds like you are making calls to Qt GUI items before you construct the QApp. Call the QApp constructor just after you enter main (before you do anything else) and see if that fits your problem... then update your program accordingly... – David Mokon Bond Mar 12 '13 at 19:02
  • I was mixing debug/release libraries. Once I get rid of the mixed calls the error disappeared. Thanks for your reply! – Adri C.S. Mar 13 '13 at 16:50

2 Answers2

3

I've found a solution: you must add a size hint for the viewer control. Something like this will be ok:

In AbstractQTGLWidget.hpp:

...
class AbstractQTGLWidget ... {
  ...
protected:
  QSize sizeHint() const { return QSize(400,300); }
  ...
};

I think (but not 100% sure) that the problem is within the constructor, when the width() and height() properties are used.

Different layouts, different priorities in establishing the width and height of each widget, and so the constructor is blind to the final width and height.

Giving an initial width and height, I assume the underlying osg viewer can calculate the camera and object references, and begin the process accordingly. Later changes in width and height are applied correctly, as the object was initiated with correct sizes, though not final.

Maybe the control thinks it has a size of 0 by 0 pixels, and the renderer gets crazy initializing...

With 0: with 0

With 1: With 1

felixgaal
  • 2,403
  • 15
  • 24
  • Oh! Almost forgot: I'm using Ubuntu 11.10 / Qt 4.7 / openscenegraph 3.0.0. Everything from official repositories – felixgaal May 21 '12 at 15:35
  • Thanks a million! Works like a charm. I'll post this over at the open scene graph group so a fix can be made. It also make sense why with one of my intersection tracers I was getting div/0 errors. I wasn't thinking that was related but I guess it was... Thanks again. – David Mokon Bond May 21 '12 at 23:54
1

I've tried reproducing the problem with the code you provided. However, I wasn't able to get the latest OpenSceneGraph (and its OpenThreads dependency) building.

So I made your example even simpler, and used a QFrame instead of the OSG widget.

Having experimented with the code quite a lot, my suggestion is to try adding a call:

 viewer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
Clare Macrae
  • 3,670
  • 2
  • 31
  • 45
  • Thanks for looking into this. I tried that to no avail. So it isn't that the OSG Widget (which contains the scene graph) doesn't have any space in the layout. Rather its that the scene graph is not rendering. I have uploaded two images of this: (http://mokon.net/ex/ss-broken.png, http://mokon.net/ex/ss-works.png). I am pretty sure it has something to do with how I am connecting the rendering. – David Mokon Bond May 13 '12 at 18:14
  • Also, at least on Fedora 16 yum install OpenSceneGraph* and yum install qt4-devel and I think that will give you all the dependencies. – David Mokon Bond May 13 '12 at 18:15