garetxe on master
haskell-gi-base 0.26.3 haskell-gi-0.26 Fix for nullable parameter in r… (compare)
haskell-gi
and haskell-gi-base
from github, the bindings themselves (the gi-*
packages) in hackage should be OK. Just make sure that they are regenerated (removing your .dist-newstyle
should do the job).
Is there an example project or howto how to use GTK4 + haskell-gi and stack?
Unfortunately nothing that I am aware of. It should be possible to do by adding enough packages to your stack.yaml
, there is some relevant discussion in haskell-gi/haskell-gi#339
cabal
before going into that. At least for building haskell-gi
generated bindings it is often easier with cabal
.
How would you translate
new Gtk.Window [ On #destroy Gtk.mainQuit ]
`
to code that doesn't use labels?
new
(from GI.Gtk) without specifying the bins type, i don't seem to be able to
myNew = new
(with GI.Gtk in scope)
• Overlapping instances for GI.Constructible a0 tag0
arising from a use of ‘GI.new’
Matching instances:
instance [overlappable] (GI.GObject a, tag ~ 'GI.AttrConstruct) =>
GI.Constructible a tag
-- Defined in ‘Data.GI.Base.Constructible’
instance (tag ~ 'GI.AttrSet) =>
GI.Constructible G.AccelGroupEntry tag
-- Defined in ‘GI.Gtk.Structs.AccelGroupEntry’
instance (tag ~ 'GI.AttrSet) => GI.Constructible G.AccelKey tag
-- Defined in ‘GI.Gtk.Structs.AccelKey’
...plus 35 others
...plus 95 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
(The choice depends on the instantiation of ‘a0, tag0’
To pick the first instance above, use IncoherentInstances
when compiling the other instance declarations)
• In the expression: GI.new
In an equation for ‘myNew’: myNew = GI.new
|
97 | myNew = G.new
| ^^^^^
boxPackStart box widget expand fill padding
widgetDestroy
which appears to trigger the crash.
I'm then destroying the widget with
widgetDestroy
which appears to trigger the crash.
This sounds a bit like you are double freeing. Is it necessary to call widgetDestroy
in your code? Every widget in Gtk is reference counted. In particular if you create a widget and add it to a box then it will have a refcount of 2: Haskell keeps one (which it will drop once the Haskell object is garbage collected) and the container keeps another.
(By the way, when debugging crashes it is useful to run with the following environment vars set:
export G_SLICE="debug-blocks"
export MALLOC_CHECK_=2
export MALLOC_PERTURB_=$(($RANDOM % 255 + 1))
export HASKELL_GI_DEBUG_MEM=1
)
And another question: how would I replicate https://hackage.haskell.org/package/gi-gtk-4.0.5/docs/GI-Gtk-Objects-Scale.html#v:scaleNew with https://hackage.haskell.org/package/haskell-gi-base-0.26.0/docs/Data-GI-Base-Constructible.html#v:new , since it has some additional parameters ?
In general it should be perfectly fine to call scaleNew
, but in this case it might be possible to make it work with new
too. Have you tried setting the orientation
and adjustment
attributes? Something like
scale <- new Gtk.Scale [#orientation := ..., #adjustment := ...]
data HPackBox = HPackBox
instance (IsDescendantOf Box a, IsDescendantOf Widget b,
Constructible b tag, MonadIO m, GObject a, GObject b,
input ~ ((a, Bool, Bool, Word32), (ManagedPtr b -> b, [AttrOp b tag])), output ~ m b) =>
ApplyAB HPackBox input output where
applyAB _ ((box, expand, fill, padding), (ctr, attrs)) = do
widget <- new ctr attrs
boxPackStart box widget expand fill padding
return widget
data HDestroyWidget = HDestroyWidget
instance (IsWidget o) => ApplyAB HDestroyWidget o (IO ()) where
applyAB _ widget = widgetDestroy widget