Results 1 to 6 of 6

Thread: qtconcurent imagescaling example upgrade

  1. #1
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default qtconcurent imagescaling example upgrade

    hello.

    i look at the example "imagescaling" and done some upgrade.

    well:

    image.h (image.cpp has all the implementation)
    Qt Code:
    1. class ImageData
    2. {
    3. //... some data for the image size and path
    4. }
    5.  
    6. class MyImage: public QWidget, public ImageData
    7. {
    8. // some function for working with images
    9. }
    To copy to clipboard, switch view to plain text mode 
    Then I have another class for working with all loaded images.

    imagelist.h
    Qt Code:
    1. class MyLsit:public QWidget
    2. {
    3. //...
    4. }
    To copy to clipboard, switch view to plain text mode 

    imageList.cpp
    Qt Code:
    1. // my function for loading image
    2. MyImage loadImage(const ImageData &data)
    3. {
    4. MyImage m;
    5. //... things to do on loading images
    6. return m;
    7. }
    8.  
    9. void MyList::FirstStep()
    10. {
    11. QList<ImageData> datalist;
    12. // load data
    13. collection= new QFutureWatcher<Image>((QObject*)this);
    14. collection->setFuture(QtConcurrent::mapped(datalist,loadImage));
    15. // etc
    16. }
    To copy to clipboard, switch view to plain text mode 

    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:
    Qt Code:
    1. QImage loadImage(const ImageData &data){...}
    To copy to clipboard, switch view to plain text mode 
    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.
    thx!

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qtconcurent imagescaling example upgrade

    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.)

  3. #3
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qtconcurent imagescaling example upgrade

    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?

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qtconcurent imagescaling example upgrade

    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!)

  5. The following user says thank you to caduel for this useful post:

    codebehind (11th September 2009)

  6. #5
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qtconcurent imagescaling example upgrade

    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.

  7. #6
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qtconcurent imagescaling example upgrade

    just read threads

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.