Answer the question
In order to leave comments, you need to log in
Why is glade not being loaded into my class?
Guys, I ask you not to hurt me, I'm learning the pros and faced such a disaster. I create a window with markup from a glade file like this:
#include <gtkmm.h>
#include <iostream>
#include "./win.cpp"
int main (int argc, char *argv[]){
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
auto refBuilder = Gtk::Builder::create();
Gtk::Window* TestWin;
//MainWindow* TestWin;
try{
refBuilder->add_from_file("./test.glade");
}
catch(const Glib::FileError& ex){
std::cerr << "!! FileError: " << ex.what() << std::endl;
}
catch(const Glib::MarkupError& ex){
std::cerr << "!! MarkupError: " << ex.what() << std::endl;
}
catch(const Gtk::BuilderError& ex){
std::cerr << "!! BuilderError: " << ex.what() << std::endl;
}
refBuilder->get_widget("window_id", TestWin);
if(TestWin)
return app->run(*TestWin);
else{
std::cout << "Ошибка загрузки виджета." << std::endl;
return 1;
}
}
class MainWindow : public Gtk::Window{
public:
virtual ~MainWindow(){
std::cout << "Окно закрыто." << std::endl;
}
protected:
void on_button_clicked(){ //Обработчик сигналов от кнопки
std::cout << "Hello World" << std::endl;
}
};
** (program:22060): CRITICAL **: 18:50:50.811: Gtk::Builder::get_widget(): dynamic_cast<> failed.
Widget loading error.
Answer the question
In order to leave comments, you need to log in
In case someone runs into the same problem, I read the official manuals for a long time and was able to understand what the jamb is. The constructor must be inherited too. Approximately like this:
MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade) : Gtk::Window(cobject);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question