Reputation: 266
I'm trying to pop up a dialog after setting up Gtkmm like so:
MainWindow::MainWindow() : public Gtk::Window { //etc etc
and in main()
Gtk::Main ginit(argc,argv);
MainWindow *mw = new MainWindow; // delcared as extern in header as well for the dialog
ginit.run(*mw);
when the necessary event gets triggered, the following code should run, but fails. Which is strange since the example on http://library.gnome.org/devel/gtkmm-tutorial/2.21/sec-dialogs-filechooserdialog.html.en compiles and runs perfectly.
Gtk::FileChooserDialog *dlg = new Gtk::FileChooserDialog(Glib::ustring("choose destination"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
dlg->set_transient_for(*mw);
dlg->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
dlg->add_button(Glib::ustring("Select"), Gtk::RESPONSE_OK);
dlg->show_all_children();
int response =dlg->run();
According to GDB, it all fails on dlg->run(); And to make it more fun, it gives me one of two errors:
(PCollab:4583): GLib-GObject-CRITICAL **: g_object_ref: assertion `G_IS_OBJECT (object)' failed
(PCollab:4583): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `-g-type-private--GTypeFlags'
(PCollab:4583): GLib-GObject-CRITICAL **: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
(PCollab:4583): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed
(PCollab:4583): GLib-GObject-CRITICAL **: g_object_ref: assertion `G_IS_OBJECT (object)' failed
(PCollab:4583): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `(null)'
(PCollab:4583): GLib-GObject-CRITICAL **: g_signal_emit_valist: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
(PCollab:4583): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed PCollab: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.
So i figured what the hell and ran
sudo xhost +
Which does some magic that allows the same program to connect twice to X11 (or so I read on the all-knowing internet) This has some effect, but not what I desire. Because now it gives me something far more cryptic:
../../src/xcb_io.c: process_responses: Assertion `(((long) (dpy->last_request_read) - (long)(dpy->request)) <= 0)' failed.
I'd assume that the first error means that mw doesn't point to a Gtk::Window as it isn't considered an object by gtk, but the fact remains that mw is shown on my screen perfectly without errors when i run Gtk::Main ginit(*mw); As I have not even the faintest idea what this means, I hope that some Gtk / X11 guru can point me in the right direction to fix my code.
Other details , i'm running Ubuntu Linux (amd64) with gcc 4.4.5 and gtkmm 2.4
Upvotes: 2
Views: 1879
Reputation: 10061
Don't know if it's really important, but try changing the line
MainWindow *mw = new MainWindow; // delcared as extern in header as well for the dialog
to
MainWindow *mw = new MainWindow(); // delcared as extern in header as well for the dialog
// Missing parentheses --------^
Upvotes: 0
Reputation: 1101
MainWindow::MainWindow() : public Gtk::Window { //etc etc
This looks a bit strange, are you trying to inherit in the definition instead of the declaration? Or is it just a typo?
The example code in the (new) tutorial (for gtkmm 3) now looks like the following.
#include <gtkmm.h>
class ExampleWindow : public Gtk::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
protected:
//Signal handlers:
void on_button_file_clicked();
void on_button_folder_clicked();
//Child widgets:
Gtk::VButtonBox m_ButtonBox;
Gtk::Button m_Button_File, m_Button_Folder;
};
Have you tried allocating the variables on the stack instead of on the heap? Like
Gtk::FileChooserDialog dialog("Please choose a folder",
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
dialog.set_transient_for(*this);
//Add response buttons the the dialog:
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
dialog.add_button("Select", Gtk::RESPONSE_OK);
int result = dialog.run();
instead of with new
and pointers?
Upvotes: 2