-2

我正在关注 Gtkmm 书籍教程,但我遇到了问题,代码已过时并且还有一些未知错误,这是我的 examplewindow.h:

#include "examplewindow.h"
#include "iostream"

HelloWorld::HelloWorld()
        : m_button("Hello World")
// creates a new button with label "Hello World".
{
// Sets the margin around the button.
    m_button.set_margin(5);
// When the button receives the "clicked" signal, it will call the
// on_button_clicked() method defined below.
    m_button.signal_clicked().connect(sigc::mem_fun(*this,
                                                    &HelloWorld::on_button_clicked));
// This packs the button into the Window (a container).
    set_child(m_button);
}
void HelloWorld::on_button_clicked()
{
    std::cout << "Hello World" << std::endl;
}

这是 examplewindows.h :

#ifndef GTKMM_EXAMPLE_HELLOWORLD_H
#define GTKMM_EXAMPLE_HELLOWORLD_H

#include <gtkmm-4.0/gtkmm/window.h>
#include<gtkmm-4.0/gtkmm/button.h>

class HelloWorld : public Gtk::Window
{
public:
HelloWorld();
protected:
//Signal handlers:
void on_button_clicked();
//Member widgets:
  Gtk::Button m_button;
};
#endif // GTKMM_EXAMPLE_HELLOWORLD_H

这是 main.cpp :

#include"examplewindow.h"
#include <gtkmm-4.0/gtkmm/application.h>

int main(int argc, char* argv[])
{
    auto app = Gtk::Application::create("org.gtkmm.example");
    HelloWorld helloworld;

    return app>make_window_and_run(helloworld, argc, argv);
};

这是我编译时得到的:

g++ main.cpp eamplewindow.cpp examplewindow.h -o -02 myfirstprogram `pkg-config gtkmm-4.0 --cflags --libs`
main.cpp: In function 'int main(int, char**)':
main.cpp:10:16: error: 'make_window_and_run' was not declared in this scope
   10 |     return app>make_window_and_run(helloworld, argc, argv);
      |                ^~~~~~~~~~~~~~~~~~~

你会注意到我写的app>make_window_and_run,这是错误的,但是当我写的时候,我app->make_window_and_run再次得到一个错误,应用程序没有在这个范围内声明。

4

0 回答 0