[Haskell-cafe] adding state in GUIs (qtHaskell)

Dan Weston westondan at imageworks.com
Thu Sep 10 14:57:26 EDT 2009


One simple solution is to leave the state in Qt.

As of Qt 4.2, in C++ you can use

   bool QObject::setProperty(const char * name, const QVariant & value)
   QVariant QObject::property(const char * name) const

to set and get properties on any QObject (hence any QWidget).

Since I believe these are (not yet) wrapped in QtHaskell, you can 
instead just create a widget that contains the state and just don't add 
it to a layout. Parent it to a widget and it will quietly disappear when 
its parent dies. If you want it to persist until you say so, don't 
parent it to anything (but then you might as well use Haskell for your 
state!)

Dan

Michael P Mossey wrote:
> I'm trying to learn qtHaskell. I realize few people on this list know anything 
> about qtHaskell, but I have a question that probably relates to all GUIs as 
> implemented in Haskell. I just need a hint that could help me figure out the 
> next step, which I might be able to infer from the qtHaskell API.
> 
> I don't think is any tutorial-type or step-by-step type documentation for 
> qtHaskell. I have sent some questions to the author of qtHaskell, David Harley, 
> but he hasn't responded yet, and anyway I don't want to trouble him every time I 
> have a question, so I'm trying to infer as much as I can.
> 
> The problem relates to state. In Qt, one adds state to a widget by subclassing 
> it and adding new member variables. For example, I want to create a widget that 
> responds to keypresses and remembers what keypresses have taken place.
> 
> I'm totally stuck on this part, because Haskell doesn't have state. There must 
> be some kind of Haskell call that adds state to a widget, but it is hard to 
> figure out from the qtHaskell examples David provides.
> 
> Thanks,
> Mike
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 



More information about the Haskell-Cafe mailing list