Re: Templates and signals
Did you not mean
Code:
plot::xSignal = new Signal<double>();
instead of
Code:
plot::xSignal = new Signal();
Also where is your constructor for Signal?
Re: Templates and signals
Just to warn you - Qt signals/slots mechanism is unable to cooperate with template classes.
Re: Templates and signals
Quote:
Originally Posted by
Timoteo
Did you not mean
Code:
plot::xSignal = new Signal<double>();
instead of
Code:
plot::xSignal = new Signal();
Also where is your constructor for Signal?
Yes, somehow chrome removed <double> so I used firefox instead and forgot to add it again.
Quote:
Originally Posted by
wysota
Just to warn you - Qt signals/slots mechanism is unable to cooperate with template classes.
Thanks for the warning.
Then I do it in some other way :)
Re: Templates and signals
As an example of something you could do, I threw together some code real quick. This uses libsigc++.
Code:
template<typename rt, typename T> class EmittingObject
{
std::tr1::shared_ptr<T> t;
sigc::signal<rt> m_signal;
public:
EmittingObject()
{
t = std::tr1::shared_ptr<T>(new T);
}
sigc::signal<rt>& getSignal() { return m_signal; }
std::tr1::shared_ptr<T> object() { return t;}
};
Code:
/*class demonstrating a trivial connection*/
class XWidget : public EmittingObject<void, QWidget>, public sigc::trackable
{
void handle_signal()
{
this->object()->close();
}
public:
XWidget()
{
getSignal().connect(sigc::mem_fun(this, &XWidget::handle_signal));
}
void doSomethingToCauseAnEmit()
{
getSignal().emit();
}
};
Code:
/*quick test piece*/
int main(int argc, char* argv[])
{
XWidget widget;
widget.object()->show();
while(widget.object()->isVisible())
{
widget.doSomethingToCauseAnEmit();
}
app.exit(0);
}
Sorry for the poor formatting, but that is Visual Assist's fault.
This is a silly example, I know. The basic concept is to sidestep Qt's signal/slot mechanism and employ another (if you truly need this type of thing, you may not!).
Re: Templates and signals
Quote:
Originally Posted by
Timoteo
As an example of something you could do, I threw together some code real quick. This uses libsigc++.
Code:
template<typename rt, typename T> class EmittingObject
{
std::tr1::shared_ptr<T> t;
sigc::signal<rt> m_signal;
public:
EmittingObject()
{
t = std::tr1::shared_ptr<T>(new T);
}
sigc::signal<rt>& getSignal() { return m_signal; }
std::tr1::shared_ptr<T> object() { return t;}
};
Code:
/*class demonstrating a trivial connection*/
class XWidget : public EmittingObject<void, QWidget>, public sigc::trackable
{
void handle_signal()
{
this->object()->close();
}
public:
XWidget()
{
getSignal().connect(sigc::mem_fun(this, &XWidget::handle_signal));
}
void doSomethingToCauseAnEmit()
{
getSignal().emit();
}
};
Code:
/*quick test piece*/
int main(int argc, char* argv[])
{
XWidget widget;
widget.object()->show();
while(widget.object()->isVisible())
{
widget.doSomethingToCauseAnEmit();
}
app.exit(0);
}
Sorry for the poor formatting, but that is Visual Assist's fault.
This is a silly example, I know. The basic concept is to sidestep Qt's signal/slot mechanism and employ another (if you truly need this type of thing, you may not!).
Thanks for the example! Taught me a lot!
I'm not sure I will use it in this project though, because I don't really need it.
But I am sure it will be usefull in my other projects! :)
Re: Templates and signals
Glad you liked it, but like I said it is not meant to be a great example - just something to show what could be a great alternative if enough time is put into it (and a better design - composition would have been more appropriate than inheritance for example).