View Full Version : qtconcurent imagescaling example upgrade

11th September 2009, 13:32

i look at the example "imagescaling" (http://doc.trolltech.com/4.4/qtconcurrent-imagescaling.html) and done some upgrade.


image.h (image.cpp has all the implementation)

class ImageData
//... some data for the image size and path

class MyImage: public QWidget, public ImageData
// some function for working with images

Then I have another class for working with all loaded images.


class MyLsit:public QWidget


// my function for loading image
MyImage loadImage(const ImageData &data)
MyImage m;
//... things to do on loading images
return m;

void MyList::FirstStep()
QList<ImageData> datalist;
// load data
collection= new QFutureWatcher<Image>((QObject*)this);
collection->setFuture(QtConcurrent::mapped(datalist,loadImage) );
// etc

when I compile the project it returns the error:

/usr/lib64/qt-4.4.1/include/QtGui/qwidget.h: In copy constructor ‘MyImage::MyImage(const MyImage&)’:
/usr/lib64/qt-4.4.1/include/QtGui/qwidget.h:750: error: ‘QWidget::QWidget(const QWidget&)’ is private
../qt4/Tools/ShowImg/image.h:18: error: within this context
../qt4/Tools/imgsched.cpp: In function ‘Image LoadImage(ImageData&)’:
../qt4/Tools/imgsched.cpp:12: note: synthesized method ‘MyImage::MyImage(const MyImage&)’ first required here

if I change MyImage with QImage:

QImage loadImage(const ImageData &data){...}
it compiles.

I think this is an C++ feature, but i can not work it out.
Any suggestion on how to implement this would be appreciate.

11th September 2009, 13:48
why does MyImage (need to) inherit from QWidget?

(QWidget -as all QObjects- can not be copied or copy-constructed, which is what your compiler is trying to tell you.)

11th September 2009, 14:05
i forgot to write a detail:
in MyImage I have overwriten the paintEvent function, because i don't use in my main widget a QLabel object where to put the image.

Is there an another way for displaying image?

11th September 2009, 14:11
you have to separate the scaling from the drawing, ie make a class that contains the image (and associated data), and, if needed, one for displaying the data

Two reasons:
* QWidgets can't be copied (no way about that) - see above
* you must access QWidgets only in the main thread (which means no using QWidgets in QtConcurrent either!)

11th September 2009, 14:19
ok. thanks for the explanation....
i'll will rework my code

you must access QWidgets only in the main thread (which means no using QWidgets in QtConcurrent either!)
could you tell me where can i read more about this? i have a big hole about this topic.

11th September 2009, 14:40
just read threads