0

I starting my in house GUI application from scratch, basically managing inventory, staffs and stuff. I do not want any affiliation with windows proprietary stuff and qt requires commercial license to sell software created. So I have chosen gtkmm + mingw + glade, having messed around long with the dev environment, have to settle on MSYS2 and not eclipse.

So now I see some problem with the signals part of gtkmm. Basically gtkmm does not allow using auto connect signals from the glade file, proven in some answered questions, due to some inherent c++ mumbo jumbo (no offence at all I am only trying to be funny) compiler removing identifiers and replacing them with pointers stuff. However I find that I really seem to need it for better code control.

So below is a simple illustration of the planned layout, fortunately part of the functionality I have in mind is working, and I have already spent days on that. enter image description here

Basically application UI is a vbox with 3 slots, populated from a glade file, top one contains menu bar, middle one contains a toolbar, bottom one contains a gtknotebook. When corresponding menu items are clicked, gtknotebook will append a page then fill up the page with the UI of a module.

So I first have to load up the application UI from a glade file using a Gtk::Builder, then in order to implement the "click menu show module" function, first I tried adding the function name that appends page to gtknotebook into the glade file, gtkmm does not support gtk_builder_connect_signals, as explained above. I later resorted to putting the list of modules into xml file, parse the content using xerces-c++, built several module UIs into a single glade file, with separate top level containers, their names correspond to the modules, then programmatically connecting the signals, something like this

struct menuItemInfo{ //struct holding necessary information to load glade and append page
    Glib::RefPtr<Gtk::Builder> builder;
    Glib::RefPtr<Gtk::Builder> modulebuilder;
    string modulerootwidgetname;
    string labelname;
};

void add(menuItemInfo data){ //function that appends page based on information
    Gtk::Frame* f;
    Gtk::Notebook* nb;
    data.builder->get_widget("modulenotebook", nb);
    data.modulebuilder->get_widget(data.modulerootwidgetname, f);

    int pageNum = nb->page_num(*f);
    if (pageNum == -1){
        Gtk::Label lb; lb = Gtk::Label(data.labelname);
        nb->append_page(*f, lb);
    }else{
        nb->set_current_page(pageNum);
    }
}

for (XMLSize_t i = 0; i < nMenu; i++){ //loop through menu items
    Gtk::MenuItem* menuItem = nullptr;
    dr->snapshotItem(i);
    menuItemInfo r1;
    r1.builder = mainBuilder;
    r1.mbuilder = modulesBuilder;
    r1.modulerootwidgetname = XMLString::transcode(dr->getNodeValue());
    r1.labelname = XMLString::transcode(dr->getSomeOtherNodeValue());
    mainBuilder->get_widget(dr->getSomeMenuNodeValue(), menuItem);

    //connects signal
    menuItem->signal_activate().connect(sigc::bind<menuItemInfo>(sigc::ptr_fun(&add),r1));
}

At first I thought it would be a good idea, I thought I had to manage modules with an xml file anyways (and it really took me days to reach here), but now I realize that I do not seem to be able to further penetrate the signals to next level apart from really hard coding. I shall need to have different signals to text views, text boxes combo lists and stuff and it is not simple as appending page and changing a single string. Then I am stuck.

Coming on to that, I was thinking of building separate classes for each module, they may inherit from the same parent as you see some of their basic functionality will be the same, they respond to some toolbar icons being clicked, and they will be closed. So I thought I could put the initialize signal connect into each class separately and call from its initializer.

Turns out it seems C++ cannot take class name as variable, because of the mumbo jumbo thing, so I still cannot manage the whole thing from external xml file. I tried looking into some factory stuff, but currently still can't get my head around it and not sure if it is relevant at all.

With despair, I tried falling back to gtk and c, and while reading up its application tutorial, the gobject concept shed some light onto my situation.

Question is, which seems a better way to go? I really want to separate the UI, program logic and modules. Is going back to C really necessary? Is GObject a work around? or as I read its the gtk implementation of object in c? Or is factory a way to go? Or use some kind of builder that hard codes for me?

I may continue to work in C, but some direction on the matter and suggestions will be nice, thank you in advance for any opinion.

Community
  • 1
  • 1
  • Doesn't GTK require to GPL your code and doesn't Qt also have a GPL licence-option? – too honest for this site Oct 18 '16 at 10:43
  • No, GTK+ is LGPL so it is perfectly acceptable to **dynamically** link it into a proprietary application. Qt has a LGPL license option, so the same point applies. You do need a commercial license for Qt if you want to do things like static linking or private modifications of Qt and keep your project proprietary. – andlabs Oct 18 '16 at 10:55
  • Haha Thank you guys for the affirmation, would really appreciate if you would go into the programming details. – Jimmy Chi Kin Chau Oct 18 '16 at 11:11
  • @andlabs is definitely correct. Abide by the LGPL and you can make the program _proprietary_ if you really want to. – oldtechaa Oct 18 '16 at 12:32
  • As for the question itself I'm not sure if it is off topic for Stack Overflow or not, but I will say understanding the C++ "mumbo jumbo" is important if you want to do C++ programming. You could probably automate the process of connecting signals without moving to C by parsing the .ui file (it's a strictly-formatted XML file), looking for signal definitions, and then generating code that connects to either top-level C functions or `static` class methods, passing the `this` pointer as the `user_data` parameter. Instance methods won't work because of the implicit `this` parameter. – andlabs Oct 18 '16 at 13:11

0 Answers0