繁体   English   中英

Gtkmm Window 为空白,不显示任何小部件或标题

[英]Gtkmm Window is blank, not showing any widgets or title

我正在学习 gtkmm 以便将康威的生命游戏编程为演示。 目前我正在尝试在 header 栏中显示两个按钮,并且我正在关注教程,但 window 中没有显示任何内容。 这是我的代码:

显示.h:

#include <gtkmm/window.h>
#include <gtkmm/headerbar.h>
#include <gtkmm/button.h>

class Display : public Gtk::Window
{
public:
    Display();
    Display(int xSize, int ySize);
    virtual ~Display();

private:
    //child widgets
    Gtk::HeaderBar mHeader;
    Gtk::Button startButton;
    Gtk::Button stopButton;

};

显示.cpp:

#include "Display.h"

Display::Display(int xSize, int ySize):
startButton("start"),
stopButton("stop"),
mHeader()
{
    //set window properties
    set_title("Conway's Game of Life");
    set_size_request(xSize, ySize);
    set_border_width(5);
    mHeader.set_title("Game of Life");

    //add to header bar
    mHeader.pack_start(startButton);
    mHeader.pack_start(stopButton);

    //add header bar
    add(mHeader);

    //make everything visible
    show_all();


}

Display::Display()
{
    Display(600, 600);
}

Display::~Display() {}

主要.cpp:

#include "Display.h"
#include <gtkmm.h>

int main(int argc, char **argv)
{
    auto app = Gtk::Application::create(argc, argv);

    Display Window; 

    return app->run(Window);
}   

我一直在尝试解决这个问题很长一段时间,但似乎无法弄清楚。 任何帮助将不胜感激。

问题是您没有正确使用构造函数委托 尝试按如下方式编写默认构造函数:

Display::Display()
: Display(600, 600) // Delegate here, not in body...
{

}

它应该可以工作。 请注意,这是 C++11 功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM