Results 1 to 8 of 8

Thread: qvtkwidget crashes when it is used inside a slot, please help

  1. #1
    Join Date
    Jan 2014
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default qvtkwidget crashes when it is used inside a slot, please help

    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
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qvtkwidget crashes when it is used inside a slot, please help

    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,
    _

  3. #3
    Join Date
    Jan 2014
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: qvtkwidget crashes when it is used inside a slot, please help

    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 !
    Last edited by Adem; 24th January 2014 at 16:32.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qvtkwidget crashes when it is used inside a slot, please help

    RenWin is null at that line. The crash message says so.

  5. #5
    Join Date
    Jan 2014
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: qvtkwidget crashes when it is used inside a slot, please help

    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

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qvtkwidget crashes when it is used inside a slot, please help

    I do not have VTK to work with, so I am working from this example:
    http://www.vtk.org/Wiki/VTK/Examples...gleInheritance

    It seems that you are creating an unnecessary vtkRenderWindow with this line:
    Qt Code:
    1. vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    To copy to clipboard, switch view to plain text mode 
    that you attach the renderer to with:
    Qt Code:
    1. renderWindow->AddRenderer(renderer);
    To copy to clipboard, switch view to plain text mode 
    You later add the same renderer instance to your widget
    Qt Code:
    1. ui->vtkwidget->GetRenderWindow()->AddRenderer(renderer);// crash
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by ChrisW67; 25th January 2014 at 01:46.

  7. #7
    Join Date
    Jan 2014
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: qvtkwidget crashes when it is used inside a slot, please help

    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...gleInheritance

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

  8. #8
    Join Date
    Jan 2014
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: qvtkwidget crashes when it is used inside a slot, please help

    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
    Attached Files Attached Files
    Last edited by Adem; 25th January 2014 at 16:23.

Similar Threads

  1. update the actor in the qvtkWidget
    By cerina in forum Newbie
    Replies: 0
    Last Post: 28th November 2012, 05:37
  2. QVTKWidget
    By floyd.pepper in forum Newbie
    Replies: 1
    Last Post: 7th March 2012, 14:15
  3. Replies: 8
    Last Post: 21st December 2011, 17:11
  4. Signal - Slot connection inside loop
    By onurozcelik in forum Qt Programming
    Replies: 5
    Last Post: 24th June 2010, 16:45
  5. QIODevice dosn't work inside slot
    By s410i in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2009, 11:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.