0
votes

I'm currently programming a little Desktop application in c++ and it's the first time, that I use gtkmm for it.

I followed the tutorials from here but all I get is a blank window. It worked before refacturing the MainWindow to its own class...

Please note: I have ommited the includes, usings and signal handler implementations.

This is my main-function:

int main(int argc, char **argv)
{
    RefPtr<Application> app = Application::create(argc, argv, "org.mw88.adbtool");
    //Main kit(argc, argv);

    RefPtr<Builder> builder = Builder::create();
    try
    {
        builder->add_from_file("Gui.glade");

        MainWindow *window = NULL;
        builder->get_widget_derived("MainWindow", window);
        app->run(*window);
        //kit.run(*window);
    }
    catch (const FileError& ex)
    {
        cerr << "FileError: " << ex.what() << endl;        
        return EXIT_FAILURE;
    }
    catch (const MarkupError& ex)
    {
        cerr << "MarkupError: " << ex.what() << endl;        
        return EXIT_FAILURE;
    }
    catch (const BuilderError& ex)
    {
        cerr << "BuilderError: " << ex.what() << endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

My MainWindow-Header:

class MainWindow : public Window
{
public:
    MainWindow(BaseObjectType* cobject, const RefPtr<Builder>& refBuilder);
    virtual ~MainWindow();
    void show(RefPtr<Application> &app);

private:
    RefPtr<Builder>     builder;
    ToolButton          *addButton;
    ToolButton          *editButton;
    ToolButton          *deleteButton;
    ToolButton          *connectButton;
    TreeView            *hostList;
    RefPtr<ListStore>   listStore; 
    Columns             cols;

    //Signal handlers:
    virtual void onAddClicked();
    virtual void onEditClicked();
    virtual void onDeleteClicked();
    virtual void onConnectClicked();  
};

This is the constructor for the MainWindow class:

MainWindow::MainWindow(BaseObjectType* cobject, const RefPtr<Builder>& refBuilder)
{
    this->builder = refBuilder;

    addButton = NULL;
    editButton = NULL;
    deleteButton = NULL;
    connectButton = NULL;
    hostList = NULL;

    builder->get_widget("hostList", hostList);

    builder->get_widget("addButton", addButton);
    addButton->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::onAddClicked));

    builder->get_widget("editButton", editButton);
    editButton->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::onEditClicked));

    builder->get_widget("deleteButton", deleteButton);
    deleteButton->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::onDeleteClicked));

    builder->get_widget("connectButton", connectButton);
    connectButton->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::onConnectClicked));

    hostList->set_model(listStore = ListStore::create(cols));
    hostList->append_column("Host", cols.host);
    hostList->append_column("Port", cols.port);

    for (int i = 0; i < 20; i++)
    {
        TreeModel::Row row = *(listStore->append());
        row[cols.host] = "Testhost";
        row[cols.port] = i;
    }

    show_all_children();
}

It seems that all Widgets are returned from the builder correctly but app->run only displays an empty Window. What could be the reason for that?

1

1 Answers

4
votes

Your constructor isn't complete, you need to initialize the base class with cObject:

MainWindow::MainWindow(BaseObjectType* cobject, const RefPtr<Builder>& refBuilder)
  : Gtk::Window(cObject)  // add this
{
    this->builder = refBuilder;
    ...