<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
David,<br>
<br>
What about making Form a template class where you define all you
need?<br>
<br>
Generally it is not recommended to do so with Qt (at the moc' time).
But you could create a template class (e.g. FormBase) which inherit
from QObject or QWidget (?), where you define all types, implements
all needed methods <b>but without</b> any signals / slots (<b>without</b>
Q_OBJECT)...<br>
Then you can inherit from this class and specialize. In this
inherited class you can now provide signals / slots (which wrap
methods from the parent class).<br>
<br>
HTH<br>
Arnaud<br>
<br>
On 02/08/2011 08:19 AM, David Doria wrote:
<blockquote
cite="mid:AANLkTi=qh2wqSWBj5bPtKefs-pvqb0MGO-vA1WX8M2vZ@mail.gmail.com"
type="cite">
<div>I frequently have this situation:</div>
<div><br>
</div>
<div>- A Qt form object called Form.</div>
<div>- I want to store an object of a class which encapsulates a
particular functionality, say ImageSegmentation in the Form
object</div>
<div>- ImageSegmentation is templated on the type of image it
should operate on, and this type is specified by a user action
at runtime</div>
<div>- Because of this, I can't store a Segmentation<T> as a
member variable in Form because I don't know T.</div>
<div>- I've been overcoming this by creating a non-templated
SegmentationBase class that I can store a pointer to in Form
(i.e. SegmentationBase* MySegmentationBase;</div>
<div>- I then instantiate the class at runtime with</div>
<div>MySegmentationBase = new
Segmentation<itk::Image<unsigned char, 2> >();</div>
<div><br>
</div>
This has been working, except that I end up jumping through hoops
to get the output of the segmentation (or whatever operation I am
doing with this pattern). That is, I want to have a
<div><br>
</div>
<div>template <typename T></div>
<div>class Segmentation : public SegmentationBase</div>
<div>{</div>
<div> T GetResult();</div>
<div>}</div>
<div><br>
</div>
<div>that I can call from:</div>
<div><br>
</div>
<div>Form::SomeFunction()</div>
<div>{</div>
<div> T result = MyImageSegmentationBase->GetResult();</div>
<div> ... do something with 'result' ...</div>
<div>}</div>
<div><br>
</div>
<div>The problem with that is two fold. </div>
<div><br>
</div>
<div>1) GetResult is only defined in Segmentation (not the Base)
because the return type is T. </div>
<div>2) I don't know T in SomeFunction(), so I can't get the value
anyway.</div>
<div><br>
</div>
<div>I tried to fix (1) by making a pure virtual GetImage() in
SegmentationBase which returns a itk::DataObject::Pointer and
also making Segmentation return a itk::DataObject::Pointer, but
it has trouble with the conversion from T::Pointer
to itk::DataObject::Pointer. But even if that worked, I'd be
stuck with (2).</div>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<div><br>
</div>
<div>Here is the whole layout:</div>
<div>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<a moz-do-not-send="true" href="http://codepad.org/lWvNYc2g">http://codepad.org/lWvNYc2g</a></div>
<div><br>
</div>
<div>Any suggestions? I hope I am just making this more
complicated than it needs to be, because it seems like a pretty
standard thing to want to do!</div>
<div><br clear="all">
Thanks,<br>
<br>
David<br>
</div>
</blockquote>
<br>
</body>
</html>