[vtkusers] Reader Update in Qt sub thread
Hu Yangsheng
hysinkmust at gmail.com
Mon Dec 11 03:10:36 EST 2017
Hello everyone,
I use Qt and VTK together,so I need to read big DICOM files in another
thread. While, there has some problems I cannot solve...
I encapsulating the VTK Reader into a Qt class called ImageReader. And
Use the ImageDataLoader starts new thread using ImageReaders to load
files.
Now I use vtkDICOMReader in DCMSegReader which is a subclass for
ImageReader. But sometimes, it will crash into
vtkObjectBase::GetClassName. I know it's a null pointer error while i
dont know why and it is not crashed in my code. so does anyone know
how to fix this ? Or could anyone give me a right code to do this
thing ?
I use the VTK 8.0.0 and Qt 5.5.1 in MSVC2013.
My code:
////////////////////////////////////////////////////////////////////////////////////////////
Class:mageDataLoader
Method:startReadThread
////////////////////////////////////////////////////////////////////////////////////////////
// init the reader
Reader->SetInputPath (CachePath);
// take it into sub thread
Reader->moveToThread (&ReadThread);
// connect signal/slot
QObject::connect (&ReadThread, SIGNAL (started ()), Reader, SLOT (ReadImage()));
QObject::connect (Reader, SIGNAL (updateProgress ()),
this, SLOT (readingProgressUpdating ()),
Qt::QueuedConnection);
QObject::connect (Reader, SIGNAL (progressSuccess ()),
this, SLOT (readingProgressSuccess ()),
Qt::QueuedConnection);
QObject::connect (Reader, SIGNAL (progressError ()),
this, SLOT (readingProgressError ()),
Qt::QueuedConnection);
ReadThread.start ();
////////////////////////////////////////////////////////////////////////////////////////////
Class:DCMSegReader
Method:ReadImage----this method will start when thread start.
////////////////////////////////////////////////////////////////////////////////////////////
void DCMSegReader::ReadImage ()
{
qDebug () << "DCMSegReader---ReadImage";
this->Reader = vtkDICOMImageReader::New ()
// Connector is a instance of vtkEventQtSlotConnect,
updateProgressCallback will emit signal updateProgress() or signal
progressError()
Connector->Connect (this->Reader, vtkCommand::ProgressEvent, this,
SLOT (updateProgressCallback ()),
NULL, 0.0, Qt::DirectConnection);
Connector->Connect (this->Reader, vtkCommand::ErrorEvent, this,
SLOT (updateProgressCallback ()),
NULL, 0.0, Qt::DirectConnection);
vtkDICOMImageReader::SafeDownCast (this->Reader)->SetDirectoryName
("D:\\I_VTK\\ImageData\\Beijing_data\\MRI_Heart");//CachePath.toLocal8Bit
().data ()
qDebug () << "DCMSegReader---Update";
this->Reader->Update ();// sometimes crash here
qDebug () << "DCMSegReader---Updated";
////////////////////////////////////////////////////////////////////////////////////////////
It will crash sometimes ,when i call this->Reader->Update(). This
error is teminated at vtkObjectBase::GetClassName().
I look forward to your answer.
Thank you!
Yangsheng Hu
More information about the vtkusers
mailing list