Windows to Linux and soon to MID

By Judy Hartley (Intel) (3 posts) on August 5, 2008 at 8:05 am

Newbie blogger here.  I’ve been working on a GUI application for MID devices that will call some APIs that are being developed simultaneously.  Because it is MID directed, I’m using a Linux OS (Ubuntu 8.04) for the first time in years.   My development system is Anjuta IDE and Glade Interface Designer.  I started using Gdk+ and C language and then “graduated” to C++ using Gdkmm.  This seems to be somewhat rarified air as there are few internet pages or posts detailing problems and solutions.  It feels like I’ve sort of kludged something together, but it works for me.  I’ve finally reached a point where the interface part of my program is working beautifully.  I thought I would take the time to write this blog and mention some of the internet sites that have helped me the most, and describe a problem I had and the solution I came up with.  Maybe some of you have had similar experiences and might know a better way.  Alternatively, this post may help someone else getting comfortable with Linux development.

 

The most interesting thing about this whole process has been the search for relevant information that combines one or more of the elements of my development environment.  You can find lots of information about GTK + in the GNOME Documentation Library, but not so much about using the Glade Interface Designer with it.  Of course, the Glade site has some documentation that helps with the program itself, but little on using it with Gtk. The Gdkmm documentation is excellent and has helped me the most.  It even includes a section on Glade and libglademm which gives a lot of information.  Down at the bottom of the page is a link to a great collection of example code.

 

Then there is C++ in Linux.  It is basically the same as in Windows, but some things are different.  I miss my CStrings.  Yeah, I know it’s a crutch, but there you go.  When I tried to use itoa, I couldn’t make it work.  I’ve learned since then that the way to call itoa on Glib is g_ascii_strtoull (Thank you, Daniel Harbin).   But I have found some interesting ways to use strings in Linux.  This site, C++ String class Examples and Tutorial is great!  It contains all the things I’d forgotten that could be done with regular strings.

 

My application is a four thread program.  It has a main GUI thread that then spawns off three additional threads.  One of these threads has a link back to the GUI class.  When it is ready, it sends data to the GUI and changes the text in some widgets.  The problem that I mentioned earlier was that although I was getting the information posted correctly, the GUI itself was not refreshing until the mouse was moved.  Since my program sends new information every second, several changes could have occurred before a mouse move triggered the update.  This just wasn’t going to work.  I tried the show(), flush(), locking the gdk_thread, even GdkWindow::invalidate_rect.  Nothing seemed to work.

 

Then someone else pointed out that I was trying to update the GUI from another thread.  Part of the solution was to set the signal in Glade to go to a signal handler when the widget was changed.  Then in the signal handler, I put in the following code:

 

          p_eEntry->show();

while(Gtk::Main::instance()->events_pending())

          Gtk::Main::instance()->interation();

 

What this code does is to tell the GUI to stop and handle all updates right away.  The solution works.  I do get a warning in the terminal that says “Glib-WARNING **: g_main_context_prepare(): main loop already active in another thread.”  I’m still researching why this happens and how to fix the warning.  Some online comments suggest that it is a bug while others say to use the “child watch” functionality of GLib. If you know of something that will help, I hope you will post a reply.  Regardless, I will post more comments as I go along with the hope that others will benefit and /or contribute.

Categories: Mobility, Open Source

Comments(4)

August 7, 2008 7:25 AM PDT


Aharon Robbins
Really neat. I think that Linux for MIDs is wonderful. My own GUI experience is with Qt 4.x, which I really really like. Is there support for Qt on MIDs? Why did you choose GTK over any other toolkit? Thanks.
August 7, 2008 11:53 AM PDT

Bill Pearson (Intel)
Total Points: 685
Status Points: 185
Brown Belt
Greta post Judy. I'm looking forward to hearing more about your Linux and MID programming adventures.
August 7, 2008 9:38 PM PDT

Jeff Moriarty (Intel)
I love that you're sharing your own experiences, Judy. This is tough for people to get into, and the more tips and advice you can offer from your own efforts will be valuable to a lot of folks.
August 8, 2008 6:15 AM PDT

Judy Hartley (Intel)
Total Points: 250
Status Points: 200
Green Belt
Hi Aharon,
I didn't so much choose GTK as it chose me :-) We had a Linux training and this was the toolkit we were introduced to, so that's what I started with. I'm not sure about Qt support for MID. I suggest you sign up for the Moblin mailing list: http://www.moblin.org/community/community_mail-list.php
. I just signed up myself to present an issue I'm having, and they will probably know the answer to your question.


Leave a comment

Name (required)

Email (required; will not be displayed on this page)

Your URL (optional)


Comment*