4

I'm trying to reproduce the example at - https://developer.gnome.org/gtkmm-tutorial/stable/sec-treeview-examples.html.en#treeview-dnd-example

Compile time error:

"make_managed" is not a member of 'Gtk' in the file treeview_withpopup.cc at the line auto item = Gtk::make_managed("_Edit", true);

The Netbeans IDE too shows an error at the same line

"Unable to resolve the identifier make_managed"

I've copied the code from the site and gtkmm.h is included in the header file.

I did not find any such question been asked on Stackoverflow yet! Why am I receiving this compile error?

Please help.

nitinr708
  • 1,393
  • 2
  • 19
  • 29
PBNeves
  • 41
  • 4
  • Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take [the SO tour](http://stackoverflow.com/tour), read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Nov 16 '18 at 09:26
  • 1
    Please ensure the gtkmm.h you are including pertains to gtkmm3 and accidently not gtkmm2 – nitinr708 Nov 16 '18 at 09:41
  • what is version of your gtkmm? try `pkg-config --modversion gtkmm-3.0` In older version of gtkmm Gtk::make_managed is not there. It is added recently. – Manthan Tilva Nov 16 '18 at 09:56
  • I'm usig gtkmm3-3.18.1 and compiling with pkg-config gtkmm-3.0 --cflags --libs – PBNeves Nov 16 '18 at 10:05

3 Answers3

5

Gtk::make_managed is defined in gtkmm-3.0/gtkmm/object.h (see this link).

I already got the same error. Then I checked file object.h but there is no make_managed function. I don't know why. I just installed from rpm packge (I used the OS Fedora 23).

My solution:

I add code of make_managed in /usr/include/gtkmm-3.0/gtkmm/object:

template<class T, class... T_Args>
auto make_managed(T_Args&&... args) -> T* // Note: Edited to add return type here!
{
  return manage(new T(std::forward<T_Args>(args)...));
}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
GAVD
  • 1,977
  • 3
  • 22
  • 40
  • 1
    Note: if you try to copy-past some example you are probably calling `Gtk::make_managed`... for this, you should also wrap the function in the namespace Gtk. – user2546926 Sep 29 '19 at 21:08
  • Same observation using the gtkmm 3.22.2-2 included in my vcpkg tree. The function definition has been removed. Inserting this code exposes it again as a member of the Gtk:: namespace. – Pete May 07 '20 at 16:45
1

The answer provided by @GAVD and edited by @Ayxan is correct.

Place the object.h file linked by the that answer in the directory with your source code.


Add an #include "object.h" before the other #include \<gtkmm-whatevers\>.
The make_managed function should resolve. Make sure that you remove this temporary fix when an updated version of gtkmm is fixes the problem permanently.

Or follow your local procedures to update /usr/include/gtkmm-3.0/gtkmm/object.h

I found that I also had to add the compiler flag -std=c++14 or -std=gnu++14 because of the way the make_managed function uses type auto. Adding the compiler flag changes the expected C++ language level from the default to the 2014 standard.

cbcalvin
  • 25
  • 1
  • 4
0

Just to compile the example given on the following page:

https://developer.gnome.org/gtkmm-tutorial/stable/sec-range-example.html.en

I have added the following code fragment (thanks @GAVD) into the top of examplewindow.cc

namespace Gtk
{
  template<class T, class... T_Args>
  auto make_managed(T_Args&&... args) -> T*
  {
    return manage(new T(std::forward<T_Args>(args)...));
  }
}

and the example had been successfully compiled (no needs to modify standard files)