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

时间:2018-03-12 14:15:25

标签: c++ windows-10 cygwin gtkmm

我有一个简单的程序,可以与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和MacO中工作得很完美。 我试图用相同的结果构建gnome网站的例子。

的main.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);
}

MainWindow.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;
}

1 个答案:

答案 0 :(得分:0)

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