1

I get this warning every time I launch a simple GTK application:

GLib-GIO-WARNING **: HH:MM:SS.XXX: Your application does not implement g_application_activate() and has no handlers connected to the 'activate' signal.  It should do one of these.

This is the app full code:

extern crate glib;
extern crate gio;
extern crate gtk;

use gtk::prelude::*;
use gio::prelude::*;
use std::env::args;

fn build_ui(application: &gtk::Application) {
    let builder = gtk::Builder::from_string(include_str!("ui.glade"));
    let win: gtk::ApplicationWindow = builder.get_object("application_window").expect("err build win");
    win.set_application(Some(application));
    win.set_title("Test");
    win.set_position(gtk::WindowPosition::Center);
    win.show_all();
}

// Init app
fn main() {
    if gtk::init().is_err() {
        println!("Failed to initialize GTK.");
        return;
    }

    let application = gtk::Application::new(
        Some("com.github.gtk-rs.examples.cairotest"),
        Default::default(),
    )
    .expect("Initialization failed...");

    application.connect_startup(move |app| {
        build_ui(app);
    });

    application.run(&args().collect::<Vec<_>>());
}

Am I doing something wrong? Is it because of the glade builder? I tried with this method, but it makes things worst: the app still compiles, but the output throw an additional critical error:

GLib-GIO-CRITICAL **: HH:MM:SS.XXX: g_application_activate: assertion 'application->priv->is_registered' failed
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Cromo
  • 169
  • 8
  • 1
    The error message is quite clear here :-) Have you tried using `connect_activate()` instead of `connect_startup()`? (the latter is a very specific signal in the timeline of a gtk::Application, and not the one you want here. – nielsdg Oct 28 '20 at 17:10
  • I thought `connect_startup()` was mandatory because I found it in a basic example somewhere. I thought `connect_activate()` was supplementary, not alternative to `connect_startup()`. I was wrong. I'm sorry for this kind of noob question but I'm new both to gtk and rust, so I do mistakes. Thank you again – Cromo Oct 28 '20 at 17:18
  • 1
    No need to apologize. Everyone makes mistakes, and for sure the documentation can be better ;-) Note that you can also always find inspiration on how to do things by looking at the gtk-rs examples https://github.com/gtk-rs/examples/tree/master/src/bin – nielsdg Oct 28 '20 at 18:06

0 Answers0