I'm trying to get the right structure for my first gtk application which will simulate a board game. I have a single command line argument which is a filename. I'm going to read this file within my gtk application. How do I access the argument outside of main()?
Here's my main() routine.
int main(int argc, char* argv[]) {
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
ExampleWindow window;
return app->run(window);
}
Here's ExampleWindow's constructor:
ExampleWindow::ExampleWindow() {
Board bd = Board(argv[1]);
...
The error I get is:
In constructor 'ExampleWindow::ExampleWindow()':
error: 'argv' was not declared in this scope
I'm thinking most of my logic will be in ExampleWindow since that listens for events. A Board class will be instantiated in the ExampleWindow constructor which will hold my data structures. The Board class constructor takes a filename as an argument to it's constructor, reads a description file, and sets up member variables based on file input.
I've spent hours on this, and find the documenation sparse and confusing. I'm using gtk 3.0 and basing my program off the Drawing Thin Lines example. https://developer.gnome.org/gtkmm-tutorial/3.4/sec-cairo-drawing-lines.html.en
Any help for a beginner in gtkmm would be appreciated.
Mabye I am on the wrong way, but why you dont pass the argc/argv to your window class?
int main(int argc, char* argv[]) {
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
ExampleWindow window(argc,argv);
return app->run(window);
}
ExampleWindow::ExampleWindow(int argc, char* argv[]) {
Board bd = Board(argv[1]);