Re: How to use Pango::Context?
Daniel Boles via gtkmm-list <[email protected]> Mon, 21 Feb 2022 14:33:28 +0000
| Newsgroups | gmane.comp.gnome.gtkmm |
|---|---|
| Message-ID | <CAKChMKPc7U0F4aHuGw1UapgLhL3g1Yg6J_KYzc4P6STmPpvB4g@mail.gmail.com> |
--===============1228155370102259808== Content-Type: multipart/alternative; boundary="00000000000076ae3005d8881ed4" --00000000000076ae3005d8881ed4 Content-Type: text/plain; charset="UTF-8" does the error occur if you do windows.reserve(2) before the emplace_back()s? On Mon, 21 Feb 2022, 14:30 phosit--- via gtkmm-list, <[email protected]> wrote: > Hello > I try to list the awailable font-families. > If I open and close multiple windows ther is a critical error: > GLib-GObject-CRITICAL **: 15:22:32.722: g_object_unref: assertion > 'G_IS_OBJECT (object)' failed > > This is the code, the error ocours even without the uncomented code: > > #include <gtkmm/application.h> > #includs thee <gtkmm/window.h> > #include <gtkmm/textview.h> > > class Window: public Gtk::Window > { > public: > Window() > { > this->show(); > this->set_child(this->text); > > auto context = this->text.create_pango_context(); > auto fontMap = context->get_font_map(); > // auto fontList = fontMap->list_families(); > // auto buffer = this->text.get_buffer(); > // auto iter = buffer->get_iter_at_offset(0); > // for(const auto& fam : fontList) > // { > // iter = buffer->insert(iter, > // fam->get_name() + '\n'); > // } > // } > > private: > Gtk::TextView text; > }; > > auto main() -> int > { > std::vector<Window> windows; > auto app = Gtk::Application::create(); > > app->signal_activate().connect([&] > { > auto& w0 = windows.emplace_back(); > app->add_window(w0); > auto& w1 = windows.emplace_back(); > app->add_window(w1); > }); > > return app->run(); > } > _______________________________________________ > gtkmm-list mailing list > [email protected] > https://mail.gnome.org/mailman/listinfo/gtkmm-list > --00000000000076ae3005d8881ed4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto"><div>does the error occur if you do windows.reserve(2) be= fore the emplace_back()s?</div><div dir=3D"auto"><br><br><div class=3D"gmai= l_quote" dir=3D"auto"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, 21 Feb = 2022, 14:30 phosit--- via gtkmm-list, <<a href=3D"mailto:gtkmm-list@gnom= e.org">[email protected]</a>> wrote:<br></div><blockquote class=3D"gm= ail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-le= ft:1ex">Hello<br> I try to list the awailable font-families.<br> If I open and close multiple windows ther is a critical error:<br> GLib-GObject-CRITICAL **: 15:22:32.722: g_object_unref: assertion<br> 'G_IS_OBJECT (object)' failed<br> <br> This is the code, the error ocours even without the uncomented code:<br> <br> #include <gtkmm/application.h><br> #includs thee <gtkmm/window.h><br> #include <gtkmm/textview.h><br> <br> class Window: public Gtk::Window<br> {<br> public:<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 Window()<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 this->show();<br= > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 this->set_child(= this->text);<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto context =3D th= is->text.create_pango_context();<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto fontMap =3D co= ntext->get_font_map();<br> //=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto fontList =3D fontMa= p->list_families();<br> //=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto buffer =3D this->= ;text.get_buffer();<br> //=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto iter =3D buffer->= ;get_iter_at_offset(0);<br> //=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for(const auto& fam = : fontList)<br> //=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {<br> //=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 iter =3D buffer->insert(iter,<br> //=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fam->get_name() + '\n');<br> //=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br> //=C2=A0 =C2=A0 =C2=A0 }<br> <br> private:<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 Gtk::TextView text;<br> };<br> <br> auto main() -> int<br> {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 std::vector<Window> windows;<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto app =3D Gtk::Application::create();<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 app->signal_activate().connect([&]<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto& w0 =3D wi= ndows.emplace_back();<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 app->add_window(= w0);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto& w1 =3D wi= ndows.emplace_back();<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 app->add_window(= w1);<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 });<br> <br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return app->run();<br> }<br> _______________________________________________<br> gtkmm-list mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank" rel=3D"noreferrer= ">[email protected]</a><br> <a href=3D"https://mail.gnome.org/mailman/listinfo/gtkmm-list" rel=3D"noref= errer noreferrer" target=3D"_blank">https://mail.gnome.org/mailman/listinfo= /gtkmm-list</a><br> </blockquote></div></div></div> --00000000000076ae3005d8881ed4-- --===============1228155370102259808== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ gtkmm-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/gtkmm-list --===============1228155370102259808==--