Results 1 to 3 of 3

Thread: passing image to other class

  1. #1
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    1

    Default passing image to other class

    Hello!

    I've written a class wich looks like this:


    class ImageViewer
    {


    public:
    ImageViewer();
    QImage image;

    ....

    }


    I would like to use image in another class methods. How to do it??

  2. #2
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Qt products
    Qt4
    Platforms
    Symbian S60
    Thanks
    38
    Thanked 19 Times in 19 Posts

    Default Re: passing image to other class

    call the variable from the object, like, for instance:

    Qt Code:
    1. ImageViewer* myImage = new ImageViewer();
    2. ...
    3. ...
    4. ...
    5. ...
    6. QImage objImageViewer = myImage->image;
    To copy to clipboard, switch view to plain text mode 

    but please note this is a C++ question, no QT question.

  3. The following user says thank you to jano_alex_es for this useful post:

    zawal (15th September 2009)

  4. #3
    Join Date
    Jul 2009
    Posts
    9
    Thanks
    1

    Default Re: passing image to other class

    I've got still issue with it

    my code looks like this:

    first there is a main function where I create ImageViewer instance:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4. ImageViewer imageViewer;
    5. imageViewer.show();
    6. return app.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    later on there is a class, where is an QImage object created as public:

    Qt Code:
    1. class ImageViewer
    2. {
    3.  
    4.  
    5. public:
    6. ImageViewer();
    7. QImage image;
    8.  
    9. ....
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 


    and then I've got other class which constructor look like this:

    Qt Code:
    1. SceneWindow::SceneWindow()
    2.  
    3. {
    4. QPixmap pixmap=QPixmap::fromImage(imageViewer->image);
    5. ...
    To copy to clipboard, switch view to plain text mode 

    and compiler output is:

    scenewindow.cpp: In constructor `SceneWindow::SceneWindow()':
    scenewindow.cpp:10: error: `imageViewer' was not declared in this scope



    So shortly:

    we create instance of object in main(), this object contains an image and we need to use this image in method from another class.

Similar Threads

  1. sending image one class to another class
    By rajini333 in forum Qt Programming
    Replies: 4
    Last Post: 4th June 2009, 09:45
  2. Issues writing a simple image viewer class
    By ultim8 in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2009, 13:50
  3. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  4. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  5. Replies: 2
    Last Post: 27th March 2007, 12:09

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
  •  
Qt is a trademark of The Qt Company.