0

It seems to be working if only GTK4 widgets are used. If i add libadwaita widgets though the thing builds fine but crashes during runtime. Libadwaita bindings work fine when used without Gtk.Builder

Go code:

package main

import (
    "os"

    _ "embed"

    "github.com/diamondburned/gotk4/pkg/gio/v2"
    "github.com/diamondburned/gotk4/pkg/gtk/v4"
)

//go:embed main.ui
var uiXML string

// Global pointer to appobj
var appobj struct {
    window              *gtk.Window
    welcome_open_button *gtk.Button
    top_stack           *gtk.Stack
    welcome_page        *gtk.StackPage
    main_page           *gtk.StackPage
}

func main() {
    app := gtk.NewApplication("com.aesistril.dictthing", gio.ApplicationDefaultFlags)
    app.ConnectActivate(func() { activate(app) })

    if code := app.Run(os.Args); code > 0 {
        os.Exit(code)
    }
}

func activate(app *gtk.Application) {
    builder := gtk.NewBuilderFromString(uiXML)

    // Initialize global appobj
    appobj.window = builder.GetObject("mainwin").Cast().(*gtk.Window)
    appobj.welcome_open_button = builder.GetObject("welcome_open_button").Cast().(*gtk.Button)
    appobj.top_stack = builder.GetObject("top_stack").Cast().(*gtk.Stack)
    appobj.welcome_page = builder.GetObject("welcome_page").Cast().(*gtk.StackPage)
    appobj.main_page = builder.GetObject("main_page").Cast().(*gtk.StackPage)

    // Set the initial visible child to welcome_page
    appobj.top_stack.SetVisibleChild(appobj.welcome_page.Child())

    // Connect the button to switch pages
    appobj.welcome_open_button.Connect("clicked", func() {
        appobj.top_stack.SetVisibleChild(appobj.main_page.Child())
    })

    // Add the window, casting adw.Window to gtk.Window
    app.AddWindow(appobj.window.Cast().(*gtk.Window))
}

Error:

ERROR failed to add UI: .:17:1 Invalid object type 'AdwToolbarView' priority=3 code_file=../gtk/gtk/gtkbuilder.c code_line=3235 code_func=gtk_builder_new_from_string glib_domain=Gtk
SIGTRAP: trace trap
PC=0x792373dca248 m=0 sigcode=128
signal arrived during cgo execution

And here's the UI definition: https://pastebin.com/hU0SEQws

Edit: nvm solved it. go linter deleted my libadwaita import without asking me

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.