LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-21-2012, 10:54 AM   #1
Hvl
LQ Newbie
 
Registered: Apr 2010
Posts: 6

Rep: Reputation: 0
gtkmm: show() doesn't show the window when adding windows from other places than main()


Hello

Anyone here who knows gtkmm? I'm in the progress of learning it, and now I'm stuck. What I want to do is to first create a window, for example a typical "New Project" window. This New Project window is added from main, like this:
main.cpp
Code:
int main(int argc, char** argv){
	//tk_init(&argc, &argv);
	Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.control");

	NewProject newProject;
	return app->run(newProject);
}
Code:
class NewProject : public Gtk::Window{
	private:
		//Stuff for the "new_project" window
		Gtk::Label locationLabel;
		Gtk::Entry  locationEntry;
		
		Gtk::Label descriptionLabel;
		Gtk::Entry descriptionEntry;
		
		Gtk::Button createButton;
		Gtk::Grid grid;

		void CreateProject();//Callback for createButton
	public:
		NewProject();
		virtual ~NewProject();
		


};
NewProject::NewProject() : locationLabel("Location"), descriptionLabel("Description and notes"), createButton("Create") { set_title("New Project"); add(grid); //gtk_grid_set_column_spacing(GTK_GRID(grid), 5); //gtk_grid_set_row_spacing(GTK_GRID(grid), 5); grid.add(locationLabel); grid.add(locationEntry); grid.attach_next_to(descriptionLabel, locationLabel, Gtk::POS_BOTTOM, 1, 1); grid.attach_next_to(descriptionEntry, locationEntry, Gtk::POS_BOTTOM, 1, 1); grid.attach_next_to(createButton, descriptionLabel, Gtk::POS_BOTTOM, 2, 1); //locationEntry.show(); createButton.signal_clicked().connect(sigc::mem_fun(*this, &NewProject::CreateProject)); show_all_children(); show(); } NewProject::~NewProject(){ } void NewProject::CreateProject(){ gProject.location = locationEntry.get_text(); gProject.description = locationEntry.get_text(); //printf(gProject.location.c_str()); //printf(locationEntry.get_text().c_str()); Glib::RefPtr<Gtk::Application> app = get_application(); //std::vector<Window*> windows = app->get_windows(); MainWindow mainWindow; app->add_window(mainWindow); //mainWindow.Create(); //Create just calls show() on the window, tried it as a simple double check, didn't work hide(); }
And MainWindow is defined like this:
Code:
class MainWindow : public Gtk::Window{

	private:
	 	Gtk::Button testLabel;		
	
	public:
		void Create();
		MainWindow();
		virtual ~MainWindow();
};
Code:
MainWindow::MainWindow(){
	printf(gProject.location.c_str());

	if(gProject.location.empty()){
		printf("EMPTY");
	}else{
		printf("Notempty");
	}
	set_title("asd");
	Gtk::Button testButton("TEST");
	add(testButton);
	testButton.show();
	show();	
	
	//this->project = project;

	//Show the new project window
	//Glib::RefPtr<Gtk::Application> app = get_application();
	//app->add_window(newProject);

}



MainWindow::~MainWindow(){

}

void MainWindow::Create(){

	show();
}
So, why doesn't the window show up? I know the code is executed, because I can the the printf() output in the terminal. Instead of showing the new window, the application just exits successfully. If I open MainWindow from main, the windows shows up, but opening NewProject from MainWindow doesn't work.

As I said, I'm pretty new to GTK programming, so I am not completely sure about how I should organize the code, so what I've done here might for what I now, be completely wrong.

Thank you I can post more code if needed, but I don't think there is any more GTK relevant code in the project.

Last edited by Hvl; 06-21-2012 at 10:56 AM. Reason: Wrong title
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C GTK+: String returned by gtk_file_chooser_get_filename gives segmentation fault youarefunny Programming 2 10-05-2010 05:50 PM
C program calling assembly - results in segmentation fault Filipe Programming 2 11-03-2008 12:53 PM
Segmentation Fault - Gtk Static App boogy Programming 2 01-22-2007 07:44 AM
Qt application: segmentation fault error dr_berta Programming 2 10-24-2005 04:20 PM
segmentation fault with my Gtk Application jaganmolleti Programming 1 03-18-2003 12:05 PM


All times are GMT -5. The time now is 09:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration