[vtkusers] VTK and QT headaches

Alex Southern mrapsouthern at gmail.com
Tue Dec 14 08:45:16 EST 2010


Hi,

Im running a QThread event loop and trying to execute a 
vtkInteractorWindow->Render() command after each iteration. I have tried 
two approaches so far but neither work well.

The First approach, gives a VTK error and is based on something like this:
At the initialization stage I pass a pointer to iren. Then in the run() 
function I execute iren->Render();

class myThread : public QThread
{
     Q_OBJECT

  public:
      vtkRenderWindowInteractor *iren;
      void run();
     {
         for (int i = 0; i < 2000; i++)
         {
             // process some data
             iren->Render();
         }
     }
};

This compiles but gives the error in the vtkOutputWindow on each call of 
Render()....

ERROR: In ..\..\Source\VTKGit\Rendering\vtkWin32OpenGLRenderWindow.cxx, 
line 247
vtkWin32OpenGLRenderWindow (05153168): wglMakeCurrent failed in 
MakeCurrent(), error: The requested resource is in use.

The second approach gives no errors, but results in a very jerky 
interaction. It is implemented by emitting a signal from the for loop 
after every iteration. The threads myRender() signal is connected to a 
updateRenderWindow() slot function i.e.

class myThread : public QThread
{
     Q_OBJECT

  public:
      void run()
     {
         for (int i = 0; i < 2000; i++)
         {
             // process some data
             emit myRender();
         }
     }
   signals:
      void myRender();
};

class myWindow : public QMainWindow
{
     Q_OBJECT

public:
     myThread Td;
     vtkRenderWindowInteractor *iren;

public slots:
     void updateRenderWindow()
     {
         iren->Render();
     }
}


Does anyone have any suggestions as to how I can improve either of these 
methods to give a better interaction?

Thanks
Alex






More information about the vtkusers mailing list