title: Pass a QImage object between class methods
body: <p>I have two functions. In one function, i have a <code>QImage</code> and then i want to pass that QImage to another function. Both the function have different Arguments. Please tell me how can i do it?</p>
  
  <h3>CMakeLists.txt</h3>
  
  <pre><code>cmake_minimum_required(VERSION 2.4.6)
  include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
  
  rosbuild_init()
  
  
  # Qt #####################################################
  find_package(Qt4 REQUIRED)
  
  set( QT_USE_QTGUI TRUE )
  
  include(${QT_USE_FILE})
  
  
  add_definitions (-DQT_NO_KEYWORDS)
  
  # All source files
  set(SELECTION_INTERFACE_SOURCE_CPP
      src/SelectionInterface.cpp)
  
  # All header files that use Qt Keywords (e.g. OBJECT)
  set(SELECTION_INTERFACE_MOC_H
      src/SelectionInterface.h
  
  )
  
  # Wrap for MOC
  qt4_wrap_ui (SELECTION_INTERFACE_UI_H ${SELECTION_INTERFACE_UI})
  qt4_wrap_cpp(SELECTION_INTERFACE_MOC ${SELECTION_INTERFACE_MOC_H})
  
  rosbuild_add_library (selection_interface_lib
      ${SELECTION_INTERFACE_SOURCE_CPP}
      ${SELECTION_INTERFACE_MOC})
  
  
  #set the default path for built executables to the "bin" directory
  set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
  #set the default path for built libraries to the "lib" directory
  set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
  
  rosbuild_add_executable(newtest_node src/SelectionInterface.cpp)
  target_link_libraries (newtest_node selection_interface_lib ${QT_LIBRARIES})
  </code></pre>
  
  <h3>Makefile</h3>
  
  <pre><code>include $(shell rospack find mk)/cmake.mk
  </code></pre>
  
  <h3>manifest</h3>
  
  <pre><code>&lt;package&gt;
    &lt;description brief="newTestCode"&gt;
  
       newTestCode
  
    &lt;/description&gt;
    &lt;author&gt;admin&lt;/author&gt;
    &lt;license&gt;BSD&lt;/license&gt;
    &lt;review status="unreviewed" notes=""/&gt;
    &lt;url&gt;http://ros.org/wiki/newTestCode&lt;/url&gt;
    &lt;depend package="roscpp"/&gt;
    &lt;depend package="sensor_msgs"/&gt;
    &lt;depend package="std_msgs"/&gt;
  
  &lt;/package&gt;
  </code></pre>
  
  <h3>SelectionInterface.h</h3>
  
  <pre><code>#ifndef SELECTION_INTERFACE_H
  #define SELECTION_INTERFACE_H
  
      #include &lt;QApplication&gt;
      #include &lt;QtGui/QWidget&gt;
      #include &lt;QtGui/QMenu&gt;
      #include &lt;QtGui/QAction&gt;
      #include &lt;QMainWindow&gt;
      #include &lt;QDebug&gt;
      #include &lt;QLabel&gt;
      #include &lt;QGraphicsPixmapItem&gt;
  
      class Image:public QMainWindow
      {
          Q_OBJECT
  
          public:
  
              void getImage();
              void displayImage();
              QImage tempImage;
      };
      #endif 
  </code></pre>
  
  <h3>SelectionInterface.cpp</h3>
  
  <pre><code>#include "SelectionInterface.h"
  
  void Image::getImage()
  {
      QImage myImage("/home/usr/Pictures/image.jpg");
  
      qDebug() &lt;&lt; myImage.height();
  
      tempImage= myImage.copy();
  
  }
  
  void Image::displayImage()
  {
      QImage finalImage = tempImage;
  
      qDebug()&lt;&lt;finalImage.height();
  }
  
  
  int main (int argc, char** argv)
  {
      QApplication app(argc, argv);
  
      Image object;
      object.getImage();
      object.displayImage();
      object.show();
  
      return app.exec();
  }
  </code></pre>