Bug or bad use? (related to the main loop)



Hello everybody,
I've written a small event-driven application (using libsigc++) and I need to add my event manager checking function in the main loop, but before that I've test things, here my test code :
#include <iostream>

#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/box.h>
#include <gtkmm/entry.h>



namespace
{
   class MyMain : public Gtk::Main
   {
     public :
       MyMain (int argc, char* argv [])
           : Gtk::Main (argc, argv) {}

       void run ()
       {
           iteration (false);
           for (bool Exit (false) ; !Exit ; )
               while (Gtk::Main::events_pending())
                  std::cout << (Exit = iteration()) << std::endl;

           std::cout << "Leaving run() ..." << std::endl;

       } // run()

   }; // MyMain


   void Display () throw()
   {
       static int Cpt (0);
       std::cout << "You've pressed <Enter> !" << std::endl;
       if (++Cpt == 3) MyMain::quit();

   } // Display()

} // anonymous namespace



int main (int argc, char* argv [])
{
   MyMain M (argc, argv);
   Gtk::Entry E;
   Gtk::Window W;
   E.signal_activate().connect (sigc::ptr_fun (&Display));
   W.add (E);
   W.show_all();
   M.run();

   return 0;

} // main()

(I know, the static variable in Display() is awful, but that's just for testing purpose ;) In the documentation, Gtk::Main::iteration() is supposed to return true if quit() is called, but like this, the program display a list of '1' (iteration() returning true) and exit immediatly.
If you change the loop like this :
           for (bool Exit (true) ; Exit ; )
The program run as expected, until quit() is called by Display() : there isn't any 'O' that output but a gtk error msg : (test:2771): Gtk-CRITICAL **: file gtkmain.c: line 1231 (gtk_main_quit): assertion `main_loops != NULL' failed
and the loop doesn't stop.

Is there any other function I've to call in the loop before of while running or it is a bug?

Thank you very much
Romain

P.S : Since it's my first mail on this list, I would like to congratulate the gtkmm developers for their awesome work! Keep this way!





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]