title: How to make a function to be a slot temporally in Qt?
body: <p>To make a function of a class to be a slot, the class has to inherit from QObject. However, QObject takes up a quite large amount of memory. I am not sure how much it is and if the memory is for each class or each object. My code has many small data whose functions can be a slot sometime. I am wonder if there is a way to make a function of class to be a slot temporally when using it. After using it, the memory for the slot cost will be deleted. The following code illustrates the requirement.</p>
  
  <pre><code>class SmallData // size of 2 or 3 integers.
  {
  public:
      virtual void F(); // use it as a slot.
      virtual QMenu* createMenu(); // use this to create the context menu with
                                   // an action connected to F()
      ...
  };
  
  // use the small data
  vector&lt;SmallData&gt; vec(1000000); // the vector is put at a tree view. When an
                                  // item in the tree view is selected, a context
                                  // menu pop up with an action to run F().
  SmallData* data = treeView.selectedItem();    
  connect(action, SIGNAL(triggered()), data, SLOT(F())); // How to make F() to be
                                                         // a slot just here.
                                                         // The action is from 
                                                         // data-&gt;createMenu().
  </code></pre>