Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-28-2007, 02:23 PM   #1
Senior Member
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
Gtkmm main loop

So, I have a gtkmm application in which one class is responsible for encapsulating what comes out of a pipe. All the data isn't going to hit the pipe at once though, so I can't just do a bunch of blocking fgetc()'s. I tried some awkward solution about spawning off a separate thread which watched the file descriptor, but that eventually led to needing to update the GUI in this separate thread, which is a big no-no since gtkmm is not threadsafe.

I've done a fair amount of work with gtk and in gtk I would just have the main loop poll the file descriptor for me. I would like to do the same thing in gtkmm, however the function to instruct the main loop to poll a file descriptor was a method of the glib main loop. In gtk this wasn't a problem because the gtk main loop was just a glib main loop. However, in the gtkmm documentation the Gtk::Main claims to inherit only from sigc::trackable, not Glib::Main, and the method I need is a method of Glib::MainContext.

So is Gtk::Main a child of Glib::Main and it's not documented or is there another way to get the main loop to poll a file descriptor for you?
Old 09-28-2007, 11:59 PM   #2
Senior Member
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Original Poster
Rep: Reputation: 48
Okay, so I just tried it so what did and did not work. I used this line to register my callback and file descriptor
Glib::signal_io().connect(sigc::mem_fun(*this, &Action::onPoll), from, Glib::IO_IN | Glib::IO_HUP);
Which should, as I understand it, read something like this.
"Glib::signal_io()" Get the default signal-io object
"connect" Connect a file descriptor
"sigc::mem_fun(*this, &Action:nPoll)" The slot referring to the callback method.
"from" the name of the file descriptor
"Glib::IO_IN | Glib::IO_HUP" call the callback when there is data to read or the file descriptor closes

This works partially, the callback is being called for the HUP, but not when there's new I/O.


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
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 03:50 AM
converting shell while loop to for loop farkus888 Programming 8 09-12-2007 02:30 AM
Exception in thread "main" java.lang.ClassFormatError: onmyown.Main (unrecognized cla zimboney Fedora 4 07-20-2007 01:00 PM
for loop only works properly on first loop symo0009 Programming 1 12-25-2005 05:17 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:17 AM.

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