PDA

View Full Version : qvtkwidget crashes when it is used inside a slot, please help



Adem
24th January 2014, 14:12
Hi all,

I have a strange problem regarding the behaviour of QVVKWidegt.

In my GUI I used a widget which is promoted to qvtkwidget inorder to visualize a 3D image.
I want the visualisation to start when I click a button (okbutton), for that, I have made signal slot connection as follows:
connect(ui->okButton, SIGNAL(clicked()),this, SLOT(VisualizeVolumes);
my code is built without any error however when I click the okbutton, I got an access violation at runtime.

When I call VisualizeVolumes as function(without slot)it works fine and even if I do the visualisation just after line ui->setupUi(this), it works as well.The crash happen only when I try to put VisualizeVolumes as slot.

I am a newbie to qt so please can you help? I am really stack and could not move?

I have attached my files for your attention

I am using itk4.4.2 vtk6 and Qt4.8.5
Thanks,
Adem

anda_skoa
24th January 2014, 14:49
Have you checked the two involved pointers? I.e. ui->vtkwidget and ui->vtkwidget->GetRenderWindow()
Are the both != 0?

What does the crash tell you, what is the stack trace?

Cheers,
_

Adem
24th January 2014, 17:32
Thanks for your reply:
this is what I get as a message:

Unhandled exception at 0x5c3d4a9a (vtkRenderingCore-6.0.dll) in main.exe: 0xC0000005: Access violation reading location 0x00000000.


and it points me to line 40 of vtkRendererCollection.cxx :

firstRen = this->GetNextRenderer(rsit);
if (firstRen == NULL)
{
// We cannot determine the number of layers because there are no
// renderers. No problem, just return.
return;
}
renWin = firstRen->GetRenderWindow();
line 40: numLayers = renWin->GetNumberOfLayers();



Sorry I am new in c++, qt, and programming , ehat do you mean by stack trace?

THanks
Adem

Added after 18 minutes:

I just checked and both pointer are not Null !

ChrisW67
24th January 2014, 21:13
RenWin is null at that line. The crash message says so.

Adem
24th January 2014, 23:15
Yes it seems that it's null and the problem comes May be from deepcopy (I tried also shallow copy) . May be I'am losing image and image2 data once they are passed in the slot, as their are pointers...
Please could you help I am really stack and I don't know how to resolve this problem.

Thanks,
Adem

ChrisW67
24th January 2014, 23:50
I do not have VTK to work with, so I am working from this example:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Qt/RenderWindowUISingleInheritance

It seems that you are creating an unnecessary vtkRenderWindow with this line:


vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();

that you attach the renderer to with:


renderWindow->AddRenderer(renderer);

You later add the same renderer instance to your widget


ui->vtkwidget->GetRenderWindow()->AddRenderer(renderer);// crash


I suspect that the unused vtkRenderWindow is taking the renderer with it when its smart pointer goes out of scope. Then the widget crashes later when it tries to use it. Try commenting both the lines I identified.

Adem
25th January 2014, 00:03
I already commented this line but the same problem still.
Actually I used the renderWindow to render the volume inside vtkrenderwindow before it is rendered inside qtwidget just to make sure that the code is working. It has no effect.
This confirm again that the problem comes when the slot is called. Option 1 and 2 as mentioned in my code work well without any problems when there is no slot call .

Hi, in the example http://www.vtk.org/Wiki/VTK/Examples/Cxx/Qt/RenderWindowUISingleInheritance

The visualisation is done inside the constructor which is already working for me.

Adem
25th January 2014, 17:23
Hi all,

My problem now is resolved, thanks to ChrisW67

I dicovred that I used to comment only one line
//renderWindow->Render();
and not the other line
//renderWindow->AddRenderer(renderer);
...sorry ChrisW67, I didnt read carefully your message as you have suggested in your message: .....Try commenting both the lines I identified. ()


So the problem is resolved by commenting both lines:
//renderWindow->AddRenderer(renderer);
//renderWindow->Render();

Thank you very much.

Can you please explain me why is this happening? I just want to understand, because if I do the visualisation inside the constructor , the problem doesn’t occur.


I have another little problem:
When I click the okay button, the volume display in the widget is not straightforward. at the beginning the widget is blank and I have to click in the widget so the volume become visible, do you have any idea how to fix this?

Many thanks for your time.

Adem

Added after 10 minutes:

I just discovred the solution for my previous little problem:
I was commenting the line:

ui->vtkwidget->update();

Now evry thing is working fine.

for your attention I attach here my files for those how may need them in the future:

(My GUI : disply itk volume in QVTKWidget when I click in a button)

Adem