无法初始化服务器 - GTKmm 和 Cygwin

Unable to init server - GTKmm and Cygwin

本文关键字:GTKmm Cygwin 服务器 初始化      更新时间:2023-10-16

我有一个简单的程序,可以与GTKmm一起使用C++,我正在尝试在Windows上构建并运行它。我可以"轻松"构建,但是当我运行它时,我收到休耕消息:

Unable to init server: Could not connect to 127.0.0.1: Connection refused
(MyProgram:12624): Gtk-WARNING **: cannot open display:

我正在使用GTKmm 3,cygwin用于工具链和cmake,在linux和MacOS中工作完美。我试图以相同的结果构建侏儒网站的示例。

主.cpp

#include <iostream>
#include <gtkmm.h>
#include "App/Desktop/Controller/Themes/Default.hpp"
#include "App/Desktop/Controller/MainWindow.hpp"
int main(int argc, char *argv[]){
  auto app = Gtk::Application::create(argc, argv, "my.application");
  /**
   * Create the MainWindow
   */
  window = new MainWindow();
  //window->show();
  /**
   * Load the Theme of Application
   */
  Default theme;
  theme.Load();
  app->run(*window);
}

主窗口.hpp

#include <iostream>
#include "MainWindow.hpp"
MainWindow::MainWindow() : Gtk::Window(), ui(new Ui::MainWindow()) {
    ui->setupUi(this);
    this->set_size_request(600, 500);
    this->refresh();
    this->ui->open.signal_button_press_event().connect(sigc::mem_fun(*this,  &MainWindow::Open));
    this->ui->quit.signal_button_press_event().connect(sigc::mem_fun(*this,  &MainWindow::Quit));
    this->ui->about.signal_button_press_event().connect(sigc::mem_fun(*this, &MainWindow::About));
}
MainWindow::~MainWindow() {
    delete ui;
}
/**
 * Display all file avaliables to the User
 */
void MainWindow::refresh() {
    /**
     * Clear the Container and Free Memory
     */
    std::vector<Gtk::Widget*> childrens = ui->container.get_children();
    for(Gtk::Widget *child : childrens){
        ui->container.remove(*child);
        delete child;
    }
    /**
     * Add the New Elements to the Grid
     */
    int column = 3, lines;
    lines = (0 / column) + 1;
    lines = lines == 1 ? 3 : lines;
    for (int i = 0; i < lines; ++i) {
        for (int j = 0; j < column; ++j) {
                Gtk::Grid *empty = new Gtk::Grid();
                empty->set_name("companyWhiteCert");
                empty->set_visible(true);
                empty->set_hexpand(true);
                empty->set_vexpand(true);
                ui->container.attach(*empty, j, i, 1, 1);
        }
    }
}
/**
 * TopBar Menu Event
 */
/**
 * Open a New File
 * @param event
 * @return
 */
bool MainWindow::Open(GdkEventButton *event) {
    std::cout << "Open" << std::endl;
    return true;
}
/**
 * Quit the Application
 * @param event
 * @return
 */
bool MainWindow::Quit(GdkEventButton* event) {
    this->hide();
    return true;
}
/**
 * Apen About Menu
 * @param event
 * @return
 */
bool MainWindow::About(GdkEventButton *event) {
    std::cout << "About" << std::endl;
    return true;
}

使用cygwin无法使用GTK,我可以弄清楚为什么它没有启动X11。我使用Mingw重建项目,并像魅力一样工作。