Re: where is error?



Just for reference, from his original message, here is the code to which Mr. Pogonyshev refers later:

#include <gtkmm/main.h>
#include <gtkmm/radioaction.h>
#include <gtkmm/stock.h>


namespace
{

  class Radio_action : public Gtk::RadioAction
  {
  public:

    Radio_action (Group& group)
      : Gtk::RadioAction (group, "test", Gtk::StockID (), "", "")
    { }
  };

}


int
main (int argc, char** argv)
{
  Gtk::Main  main (argc, argv);

  Radio_action::Group  test_group;

#if 1
  // This segfaults.
  new Radio_action (test_group);
#else
  Gtk::RadioAction::create (test_group, "test");
#endif

  return 0;
}
And now the conversation between Murray Cumming and Mr. Pogonyshev with my comments interspersed. 
Murray Cumming wrote:

Gtk::RadioAction must be used via a RefPtr, obtained via its create() function. The same is true for derived classes, so you'll need to add a create() function that returns a RefPtr.  

Paul Pogonyshev wrote:

This certainly won't help anything since the crash happens when the constructor is executed.
Maybe the crash happens because Mr. Pogonyshev is calling a protected method that could never normally be called to instantiate a Gtk::RadioAction object unless done the way he's calling it. Murray specifically told Pogonyshev that "Gtk::RadioAction must be used via a RefPtr, obtained via its create() function."
Paul Pogonyshev wrote:

Creating a RefPtr _afterwards_ won't change anything.  Calling Gtk::RadioAction::create () creates Gtk::RadioAction, not an object of the derived class.

Murray Cumming wrote:

That's why you must implement your own create() method.   

Paul Pogonyshev wrote:
Right. But I can't.
Mr. Pogonyshev, yes you can; try something like this:
<code>
#include <gtkmm/main.h>
#include <gtkmm/radioaction.h>
#include <gtkmm/stock.h>

namespace {

class Radio_action : public Gtk::RadioAction
{
public:
    Glib::RefPtr<Radio_action> create(RadioActionGroup& group) { 
        return Gtk::RadioAction::create(group,"test",Gtk::Stock::ABOUT,"",""); 
    }
protected:
    // now override to your heart's content
};

}
int main (int argc, char** argv) {
    Gtk::Main  main (argc, argv);
    RadioButtonGroup test_group;
    Glib::RefPtr<Radio_action> ra = Radio_action::create(test_group);
    return 0;
}
</code>
And finally, here is the glittering jewel of arrogance which is the straw that breaks the camel's back:
Paul Pogonyshev wrote:

It is not my library, I'm not going to debug it.  The example _only_ calls the constructor of a standard class.  If it crashes, it is not my fault, but Gtkmm's one.  (Unless you point an error in my 10 lines of code, which I doubt.)
  
I've made my living as a programmer for over twenty years and I've made use of many different GUI "libraries".   I've been using gtkmm for over three years now and I can honestly say that it ranks as one of the best I've used; and, I have yet to find a "bug" in gtkmm that didn't turn out to be of my own instigation.  Admittedly, I have not begun to delve into the more arcane where actual bugs may or may not exist, but I've made pretty extensive use of most of the features available in gtkmm.

Murray Cumming is too nice a guy to say this, but I have no qualms about it after following this thread:  Mr. Pogonyshev, why don't you listen to the advice you receive on this list and at least TRY to act on it before you start telling people like Murray Cumming that "It is not my library, I'm not going to debug it." 

Bob Caryl


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]