GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Sep 24, 2014 4:28 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Error Creating Gtk::Dialog
PostPosted: Mon Apr 01, 2013 11:51 pm 
Offline

Joined: Thu Mar 28, 2013 11:06 pm
Posts: 1
Hello!

I am trying to create a dialog when a button is cicked. The function that is called when the button is clicked is this:


Code:
void clicked(){
   std::cout << "Function Called" << std::endl;
   
   const std::string title = "Title";
   Gtk::Dialog *m_dialog(title, false);
}


I keep getting an error on the last line, where I create the Dialog.

The two errors I get are the following:
Code:
error: expression list treated as compound expression in initializer [-fpermissive]

Code:
error: cannot convert ‘bool’ to ‘Gtk::Dialog*’ in initialization


According to the gtkmm reference, the first parameter should be the title and the second should be boolean indicating if it should be a modal.

Does anyone know what I'm doing wrong?

Thanks!


Top
 Profile  
 
 Post subject: Re: Error Creating Gtk::Dialog
PostPosted: Wed Apr 03, 2013 7:42 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 747
Location: UK
Hello and welcome,

The errors you see are because you are first creating a Gtk::Dialog pointer followed by some expressions in brackets. At no point have you created a Gtk::Dialog and the expressions are in the wrong place according to the compiler.

There are two ways to correct this.

Code:
void clicked()
{
   std::cout << "Function Called" << std::endl;

   // Create a local called m_dialog
   Gtk::Dialog m_dialog("Title");

   // Use m_dialog HERE

   // m_dialog will be destroyed when out of scope
}

or
Code:
void clicked()
{
   std::cout << "Function Called" << std::endl;

   // Create a pointer called m_dialog using "new"
   Gtk::Dialog *m_dialog = new Gtk::Dialog("Title");

   // Use m_dialog HERE

   // manually delete the dialog
   delete m_dialog;
}


Which version you use depends on what you eventually need to do. Creating a pointer using new is more useful is you need to pass it around to other functions/methods. Note that I did not pass the second argument when creating the Gtk::Dialog as it already has a default value which is the same as what we want so we do not need to type it out.

_________________
E.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group