# GStreamer GTK4 TooolKit sample C++

**URL:** <https://discourse.gstreamer.org/t/gstreamer-gtk4-tooolkit-sample-c/5569>\
**Category:** General Discussion\
**Created:** [December 23, 2025, 8:36am UTC](https://discourse.gstreamer.org/t/gstreamer-gtk4-tooolkit-sample-c/5569 "2025-12-23T08:36:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![asifbahrainwala](https://discourse.gstreamer.org/user_avatar/discourse.gstreamer.org/asifbahrainwala/32/1595_2.png) [@asifbahrainwala](https://discourse.gstreamer.org/u/asifbahrainwala)\
**Post date:** [December 23, 2025, 8:36am UTC](https://discourse.gstreamer.org/t/gstreamer-gtk4-tooolkit-sample-c/5569/1 "2025-12-23T08:36:16Z")

</div>

Basic implementation of GStreamer on GTK4 Window via gtk4paintablesink

```auto
#include <bits/stdc++.h>
using namespace std;

#include <gtk/gtk.h>
#include <gst/gst.h>

GstElement *playbin=nullptr; /* Our one and only pipeline */
GstElement *gtksink=nullptr;
GdkPaintable *paintable_ptr=nullptr;
GtkWidget *picture=nullptr;

void Gstreamer()
{
    playbin = gst_element_factory_make ("playbin", "playbin");
    gtksink = gst_element_factory_make("gtk4paintablesink", NULL);

    g_object_get(gtksink, "paintable", &paintable_ptr, NULL);
    picture = gtk_picture_new_for_paintable((GdkPaintable*)paintable_ptr);
    g_object_set (playbin, "video-sink", gtksink, NULL);
    g_object_set (playbin, "uri", "https://gstreamer.freedesktop.org/data/media/sintel_trailer-480p.webm", NULL);
    gst_element_set_state (playbin, GST_STATE_PLAYING);
}

static void activate (GtkApplication *app,gpointer user_data)
{
    Gstreamer();

    auto window = gtk_application_window_new (app);
    gtk_window_set_default_size (GTK_WINDOW (window), 800, 800);

    auto label0 = gtk_label_new ("label0");
    auto label1 = gtk_label_new ("label1");

    auto placeholder0 = gtk_label_new ("placeholder0");
    auto placeholder1 = gtk_label_new ("placeholder1");

    auto notebook = gtk_notebook_new ();
    gtk_notebook_append_page (GTK_NOTEBOOK (notebook), picture, label0);
    gtk_notebook_append_page (GTK_NOTEBOOK (notebook), placeholder1, label1);

    gtk_window_set_child (GTK_WINDOW (window), notebook);
    gtk_widget_show(window);
}
int main(int argc,char *argv[])
{
    gst_init(&argc, &argv);

    auto app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
    auto status = g_application_run (G_APPLICATION (app), argc, argv);

    cout<<"picture:"<<picture->parent_instance.ref_count<<endl;
    g_object_unref (app);

    g_object_unref(gtksink);
    g_object_unref(paintable_ptr);
    g_object_unref(playbin);
    return 0;
}

```

the below header and libraries are needed to compile this

> INCLUDEPATH +=/usr/include/gtk-4.0  
> INCLUDEPATH +=/usr/include/gio-unix-2.0  
> INCLUDEPATH +=/usr/include/cairo  
> INCLUDEPATH +=/usr/include/pango-1.0  
> INCLUDEPATH +=/usr/include/harfbuzz  
> INCLUDEPATH +=/usr/include/pango-1.0  
> INCLUDEPATH +=/usr/include/fribidi  
> INCLUDEPATH +=/usr/include/harfbuzz  
> INCLUDEPATH +=/usr/include/gdk-pixbuf-2.0  
> INCLUDEPATH +=/usr/include/x86\_64-linux-gnu  
> INCLUDEPATH +=/usr/include/cairo  
> INCLUDEPATH +=/usr/include/pixman-1  
> INCLUDEPATH +=/usr/include/uuid  
> INCLUDEPATH +=/usr/include/freetype2  
> INCLUDEPATH +=/usr/include/libpng16  
> INCLUDEPATH +=/usr/include/graphene-1.0  
> INCLUDEPATH +=/usr/lib/x86\_64-linux-gnu/graphene-1.0/include  
> INCLUDEPATH +=/usr/include/libmount  
> INCLUDEPATH +=/usr/include/blkid  
> INCLUDEPATH +=/usr/include/glib-2.0  
> INCLUDEPATH +=/usr/lib/x86\_64-linux-gnu/glib-2.0/include
> 
> LIBS +=-mfpmath=sse -msse -msse2 -pthread -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk\_pixbuf-2.0 -lcairo-gobject -lcairo -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0

---

<div class="post-metadata">

**Author:** ![asifbahrainwala](https://discourse.gstreamer.org/user_avatar/discourse.gstreamer.org/asifbahrainwala/32/1595_2.png) [@asifbahrainwala](https://discourse.gstreamer.org/u/asifbahrainwala)\
**Post date:** [December 23, 2025, 8:41am UTC](https://discourse.gstreamer.org/t/gstreamer-gtk4-tooolkit-sample-c/5569/2 "2025-12-23T08:41:14Z")

</div>

some stuff I picked up from :[Gtk4paintablesink blackscreen in pure C](https://discourse.gstreamer.org/t/gtk4paintablesink-blackscreen-in-pure-c/4688)

and [https://gstreamer.freedesktop.org/documentation/tutorials/basic/toolkit-integration.html](https://gstreamer.freedesktop.org/documentation/tutorials/basic/toolkit-integration.html)

---

<div class="post-metadata">

**Author:** ![slomo](https://discourse.gstreamer.org/user_avatar/discourse.gstreamer.org/slomo/32/4_2.png) [@slomo](https://discourse.gstreamer.org/u/slomo)\
**Post date:** [December 24, 2025, 11:19am UTC](https://discourse.gstreamer.org/t/gstreamer-gtk4-tooolkit-sample-c/5569/3 "2025-12-24T11:19:50Z")

</div>

You might want to give [peel](https://gitlab.gnome.org/bugaevc/peel) a try to avoid having to write plain C code in C++, and especially to have to deal with memory management yourself.

You can find GTK4 examples inside the peel repository, and GStreamer examples [here](https://gitlab.freedesktop.org/slomo/gstreamer-peel-examples) (some depend on unmerged patches but nothing that should be relevant here).

I also had a presentation about this at the [GStreamer conference](https://gstconf.ubicast.tv/videos/a-new-era-for-gstreamer-c-bindings/) this year.

---

<div class="post-metadata">

**Author:** ![asifbahrainwala](https://discourse.gstreamer.org/user_avatar/discourse.gstreamer.org/asifbahrainwala/32/1595_2.png) [@asifbahrainwala](https://discourse.gstreamer.org/u/asifbahrainwala)\
**Post date:** [April 21, 2026, 7:26am UTC](https://discourse.gstreamer.org/t/gstreamer-gtk4-tooolkit-sample-c/5569/4 "2026-04-21T07:26:14Z")

</div>

sample code also available : [video/gtk4/examples/gtksink.py · main · GStreamer / gst-plugins-rs · GitLab](https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/blob/main/video/gtk4/examples/gtksink.py?ref_type=heads)

Notice that this sample too is using picture box

```auto
    picture = Gtk.Picture.new()
    picture.set_paintable(paintable)

```
