Note that there are some explanatory texts on larger screens.

plurals
  1. POQt signals & inheritance question
    text
    copied!<p>I am relatively new to programming with Qt and had a question. Short version:</p> <p>How do I inherit signals defined in superclasses?</p> <p>I am trying to subclass someone else's nicely made QTWidgets to change some of the default behavior:</p> <pre> //Plot3D is a QWidget that defines a signal "rotationChanged" class matLinePlot : public QObject, public Plot3D { Q_OBJECT; //etc... public: //etc... //Catch Plot3D's signal "rotationChanged" and do some magic with it: void initPlot(){ QObject::connect(this, SIGNAL(rotationChanged( double , double , double )), this, SLOT(myRotationChanged(double, double, double))); } }; </pre> <p>The problem is in the QObject::connect line. What I would like to do is connect the rotationChanged SIGNAL (from qwt3D_plot.h) to a local function/SLOT - "myRotationChanged". However whenever I do this, at run time I get:</p> <blockquote> <p>Object::connect: No such signal matLinePlot::rotationChanged(double, double, double) </p> </blockquote> <p>in C:...\matrixVisualization.h. Of course, I know that <code>rotationChanged</code> isn't in <code>matrixVisualization.h</code> - it's in <code>qwt_plot3D.h</code>, but I thought that since I inherit from <code>Plot3D</code> everything should be fine. But, now that I think about it, since SIGNAL and SLOT are macros, I assume <a href="http://en.wikipedia.org/wiki/Qt_%28toolkit%29#Meta_object_compiler" rel="noreferrer">MOC</a> doesn't know/care about inheritance.</p> <p>Which leads me to my question - since MOC and SIGNALS / SLOTS don't seem to know about inheritance etc: how can I subclass a widget defined somewhere else and get access to the widget's signals? </p> <p>I have a lot of examples of how to use encapsulation to accomplish something like this, but I'm afraid I don't understand how to do this with inheritance.</p> <p>Sorry if this is a ridiculous question - I feel like I'm missing something obvious.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload