QGraphicsView class crashes the application
-
where is this variable initialized? StationaryImageObject_
-
Hi,
Are you sure StationaryImageQListItem_ is valid ?
-
Hi,
I have used an object created from a class listWidget@
listWidget listWidgetViewerObject;
@to get the current item of the listWidget using
@
StationaryImageQListItem_ =listWidgetViewerObject.currentItem();
@
and used it in QVariant. I don't understand what's going wrong here
-
Again, are you sure that StationaryImageQListItem_ is pointing to a valid item ?
-
I tried to reimplement it in another way as
listWidget.cpp
@
QString listWidget::ConvertMovingData_()
{
QVariant MovingImageData_=item(currentRow()+1)->data(Qt::UserRole);
QString MovingData_=MovingImageData_.toString();
QFileInfo MovingImageInfo_(MovingData_);
QString MovingImageFilePath_= MovingImageInfo_.absoluteFilePath();
return MovingImageFilePath_;}
QString listWidget::ConvertStationaryData_()
{
QVariant StationaryImageData_=currentItem()->data(Qt::UserRole);
QString StationaryData_=StationaryImageData_.toString();
QFileInfo StationaryImageInfo_(StationaryData_);
QString StationaryImageFilePath_= StationaryImageInfo_.absoluteFilePath();
return StationaryImageFilePath_;}
@
listWidget.h
@
public slots:
QString ConvertMovingData_();
QString ConvertStationaryData_();
@And i used it in
movingimageviewer.cpp
@
void MovingImageViewer::setMovingImage_()
{
MovingImageScene_->removeItem(MovingImageViewItem_);
MovingImageScene_->clear();
QString MovingStringData=listWidgetMovingViewerObject.ConvertMovingData_();
MovingImagePixmap_.load(MovingStringData);
MovingImageViewItem_->setPixmap(MovingImagePixmap_);
MovingImageScene_->addItem(MovingImageViewItem_);
fitInView(MovingImageScene_->itemsBoundingRect(),Qt::IgnoreAspectRatio);
setScene(MovingImageScene_);
show();
update();
}
@similarly in
@
void StationaryImageViewer::setStationaryImage_()
{StationaryImageScene_->removeItem(StationaryImageViewItem_); StationaryImageScene_->clear(); QString StationaryStringData= listWidgetStationaryObject.ConvertStationaryData_(); StationaryImagePixmap_.load(StationaryStringData); StationaryImageViewItem_->setPixmap(StationaryImagePixmap_); StationaryImageScene_->addItem(StationaryImageViewItem_); fitInView(StationaryImageScene_->itemsBoundingRect(),Qt::IgnoreAspectRatio); setScene(StationaryImageScene_); show(); update();
}
@
-
This is the crash report for this implementation
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.yourcompany.ImageRegistration 0x0000000100055d4f listWidget::ConvertStationaryData_() + 31 (listWidget.cpp:58)
1 com.yourcompany.ImageRegistration 0x0000000100056a44 StationaryImageViewer::setStationaryImage_() + 68 (stationaryimageviewer.cpp:21)which again corresponds to the @QVariant@ implementation
-
You still don't check whether the return value of currentItem() is valid
-
Just test if the pointer is null