PDA

View Full Version : QVTKWidget doesnt work with QFileSystemModel (VTK 7, Qt 5.5)



Kind.m
2nd June 2016, 19:52
I am trying to use a VTK renderer in Qt central widget with a file explorer tree view in a QDockWidget using Qt creator 4.0. It seams that qvtkwidget doesnt work with QFileSystemModel in a QTreeView for some reason. Here is the code fragment that generate the error:'



qvtkWidget = new QVTKWidget(centralWidget)

....
QTreeView *treeView = new QTreeView(dockWidgetContents);
QFileSystemModel *dirModel = new QFileSystemModel(treeView);
QString sPath=dirModel->myComputer().toString();
dirModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs |QDir::AllEntries);
dirModel->setRootPath(sPath);
treeView->setModel(dirModel);

The above code produces a run-time error


handled exception at 0x6016A4F0 (Qt5Gui.dll) in myApp.exe: 0xC0000005: Access violation reading location 0x000000E8.

Unhandled exception at 0x6036A4F0 (Qt5Gui.dll) in myApp.exe: 0xC000041D: An unhandled exception was encountered during a user callback.

The error stops when i either remove QVTKWidget or comment out the code line



dirModel->setRootPath(sPath);


I have built VTK 7.0.0 in release mode, so I cant debug into the code. I am using installed Qt 5.5.1 built for mvsc2013 32bit on windows 10

Anyone with any idea?

d_stranz
2nd June 2016, 23:25
You will have to make a debug build in order to resolve this. It likely has nothing to do with the VTK widget, and more likely to do with 1) an uninitialized or null pointer, 2) the local declarations of "treeView" and "dirModel" pointers hiding class member variables of the same name (which are therefore unitialized), or 3) something you are doing in the "...." that corrupts memory or the stack. How do you know that dirModel->myComputer() isn't returning an empty string?

In Windows a 0xC0000005 error using means you tried to access something through an null or invalid pointer.

Kind.m
3rd June 2016, 06:21
Thank you d_stranz!

I reproduced the error on a Qt designer; I dragged and added QVTKWidget, a Dock Widget and then I dragged and added a TreeView to the Dock Widget. up to now it runs fine.

Then I added only the code lines 4,5 & 9 to 13 bellow:



ainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{

vtkRenderingOpenGL2ObjectFactory *of = vtkRenderingOpenGL2ObjectFactory::New();
vtkObjectFactory::RegisterFactory(of);

ui->setupUi(this);

QFileSystemModel *dirModel = new QFileSystemModel(ui->treeView);
QString sPath="c:/";
dirModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs |QDir::AllEntries);
dirModel->setRootPath(sPath);
ui->treeView->setModel(dirModel);

}



I just realized that the creator output also reports:


QWidget::repaint: Recursive repaint detected
The program has unexpectedly finished.

Could it be because I am using a 32bit libraries to access the file system on a 64bit system?
I am trying to building VTK with Qt support for debug mode as well as 64 bit, i did not succeed yet.

d_stranz
4th June 2016, 14:17
Could it be because I am using a 32bit libraries to access the file system on a 64bit system?

No. Your program will not link if you try to link a 64-bit program to 32-bit libraries, so therefore I assume you are building a 32-bit program. There is no problem running a 32-bit program on 64-bit Windows; you can't do the reverse.

I don't see anything wrong with the constructor; the eror must be elsewhere in your code (or in the way you are adding the VTK widget to your code.

There should be VTK examples for using VTK with Qt. Why don't you start with one of them and add your tree view and other Qt widgets to that instead of trying to add VTK to a Qt project?

The recursive paint message should be a big hint to you that your code is causing a repaint on some widget from within your paintEvent handler. If you are trying to resize a widget or do something else to it that would cause it to need to be repainted while in the paintEvent, then this will result in the error. The paintEvent is for painting, nothing else. Anything else you need to do to modify a widget's appearance has to be done elsewhere (like a resize, mouse, keyboard, hide, show, etc. event).