/* QImage* image;*/ShowImage::ShowImage(){ stop_flag=false;}void ShowImage::run(){ //для уничтожения потока setTerminationEnabled(true); AdvImage tmp = list->at(pos); image=new QImage(tmp.getPath());//tmp.getPath() - путь к изображению int temp_h = image->size().height(); int temp_w = image->size().width(); if(temp_w>temp_h)//сравнение ширины и высоты изображения { temp_h=_h; _h=_w; _w=temp_h; } *image = image->scaled(_w,_h); label->setPixmap(QPixmap::fromImage(*image)); QString s = "image is displayed"; qDebug(s.toStdString().c_str());}void ShowImage::stop(){ image->~QImage(); stop_flag=true;}void ShowImage::setValues(QLabel* img, QList<AdvImage> *_list, int index, int h, int w){ list = _list; label=img; _h=h; _w=w; pos=index;}
/*ShowImage *showimage_storage;*/void viewer::show_image(int pos){ position = pos; if(showimage_storage->isRunning()) { showimage_storage->stop(); showimage_storage->terminate(); } showimage_storage->setValues(image,image_storage,position,h,w); QString s = "start displayed image"; qDebug(s.toStdString().c_str()); showimage_storage->start();}
image=new QImage(tmp.getPath());//tmp.getPath() - путь к изображению
C++ (Qt)class MyImageLoader : public QThread {public: ... QImage mImage; bool mStopFlag; virtual void run( void ) { mImage.load(tmp.getPath()); int h = mImage.height(); if (!mStopFlag && !mImage.isNull() && mImage.width() > h) mImage = mImage.scaled(h, h); }};
В конструкторе: showimage_storage = new ShowImage(); connect (showimage_storage, SIGNAL (terminated ()), showimage_storage, SLOT (deleteLater ()));void viewer::show_image(int pos){ position = pos; if(showimage_storage->isRunning()) { showimage_storage->stop(); showimage_storage->terminate(); showimage_storage = new ShowImage(); connect (showimage_storage, SIGNAL (terminated ()), showimage_storage, SLOT (deleteLater ())); } showimage_storage->setValues(image,image_storage,position,h,w); QString s = "start displayed image"; qDebug(s.toStdString().c_str()); showimage_storage->start();}
ShowImage::~ShowImage(){ image->~QImage();}void ShowImage::run(){ //для уничтожения потока setTerminationEnabled(true);... image = new QImage(tmp.getPath());...}
void ShowImage::run(){... label->setPixmap(QPixmap::fromImage(*image));...}