Gtkmm/Gtk Gtk::Builder::create_from_source error assertion ‘GTK_IS_STYLE_PROVIDER_PRIVATE (provider)’ failed

  c++, gtk, gtkmm

I’m new to Gtkmm/Gtk and I’ve been writing some simple applications to learn how to make stuff.

I have this program called StatusBar that compiles well, but when I try to run the program the following happens:

(process:25694): Gtk-CRITICAL **: 23:03:41.036: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
(process:25694): Gtk-CRITICAL **: 23:03:41.036: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
(process:25694): Gtk-CRITICAL **: 23:03:41.036: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
Segmentation fault (core dumped)

When I debug the code this error happens when the StatusWindow constructor calls Gtk::Builder::create_from_resource().

I have already tried the following:

  • Create the Gtk::Builder from file instead of resources.

I have another program that I wrote with the same structure and it works fine.

Anyone have any idea of what is happening? I tried to look for this GTK_IS_STYLE_PROVIDER_PRIVATE (provider) assertion in Gtk source code but I hadn’t success…


The program consists of the following files:

layout.glade:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
  <requires lib="gtk+" version="3.20"/>
  <object class="GtkWindow">
    <property name="can_focus">False</property>
    <child type="titlebar">
      <placeholder/>
    </child>
    <child>
      <object class="GtkBox" id="main_box">
        <property name="name">main_box</property>
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkLabel">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="label" translatable="yes">test</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <placeholder/>
        </child>
      </object>
    </child>
  </object>
</interface>

gresources.xml

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
    <gresource prefix="/res">
        <file preprocess="xml-stripblanks">layout.glade</file>
    </gresource>
</gresources>

statuswindow.hpp

#ifndef _STATUS_WINDOW_HPP
#define _STATUS_WINDOW_HPP

#include <gtkmm/box.h>
#include <gtkmm/applicationwindow.h>
#include <gtkmm/statusbar.h>
#include <gtkmm/image.h>
#include <gtkmm/builder.h>

#include <glibmm/refptr.h>

class StatusWindow : public Gtk::ApplicationWindow {
private:
    Gtk::Box *box;
    Glib::RefPtr<Gtk::Builder> mbuilder;
public:
    StatusWindow();
    ~StatusWindow();
};

#endif // _STATUS_WINDOW_HPP

statuswindow.cpp

#include "statuswindow.hpp"

#include <gtkmm/box.h>
#include <gtkmm/applicationwindow.h>
#include <gtkmm/statusbar.h>
#include <gtkmm/image.h>
#include <gtkmm/builder.h>

#include <glibmm/ustring.h>
#include <glibmm/refptr.h>

StatusWindow::StatusWindow() : mbuilder(Gtk::Builder::create_from_resource("/res/layout.glade")) {
    mbuilder->get_widget("main_box", box);

    add(*box);

    set_title("Status Bar");
    set_default_size(400, 250);
}

StatusWindow::~StatusWindow() {
    delete box;
}

main.cpp

#include "statuswindow.hpp"

#include <gtkmm/application.h>
#include <glibmm/refptr.h>

int main() {
    StatusWindow *window = new StatusWindow();
    window->show_all();

    Glib::RefPtr<Gtk::Application> app = Gtk::Application::create("org.gtkmm.test");

    return app->run(*window);
}

And here is the Makefile:

CPP = 14
CPP_FLAGS = -g -Wall -std=c++${CPP}

GTKMM_FLAGS = `pkg-config gtkmm-3.0 --cflags --libs`

RES_FLAGS = --generate-source --target=resources.c

StatusBar: main.o statuswindow.o resources.o
    g++ -o [email protected] main.o statuswindow.o resources.o ${CPP_FLAGS} ${GTKMM_FLAGS}

main.o: main.cpp 
    g++ -c main.cpp ${CPP_FLAGS} ${GTKMM_FLAGS}

statuswindow.o: statuswindow.hpp statuswindow.cpp 
    g++ -c statuswindow.cpp ${CPP_FLAGS} ${GTKMM_FLAGS}

resources.o: resources.c
    gcc -c resources.c ${GTKMM_FLAGS}

resources.c: loading.* layout.glade
    glib-compile-resources ${RES_FLAGS} gresources.xml

clean:
    rm StatusWindow *.o

Source: Windows Questions C++

One Reply to “Gtkmm/Gtk Gtk::Builder::create_from_source error assertion ‘GTK_IS_STYLE_PROVIDER_PRIVATE (provider)’ failed”

  • The author probably already guessed where the error is.
    I will write for others who come across a similar one.
    The author forgot to add the line at the beginning of the main() function:
    gtk_init (& argc, & argv);

LEAVE A COMMENT