Re: date/time in statusbar



Anca Mitrica a écrit :

Hello,

I am working on an Gtkmm application that demands the
current date/time in  the application statusbar. I am
able to take the current time and put it in the
statusbar, but when I'm trying to display the current
time dynamically into the status bar, i get a
segmentation fault.

I am "using g_timeout_add" function to call at each
second the function that put time in the status bar.
Here is the code :

gboolean MainPage::checkTime(void){

time_t timp;
time(&timp);
Glib::ustring strtime(ctime(&timp));
// cout<<strtime<<endl;

status.statusBar->pop();
 Gtk::Label *timeLabel = new Gtk::Label(strtime);
 status.statusBar->pack_end(*timeLabel,
Gtk::PACK_SHRINK);
status.statusBar->push(strtime);

return true;

}

..............................................
g_timeout_add(1000,(GSourceFunc)checkTime(),NULL);

Can anyone tell me what is wrong with my code or give
me an idea how to do this?

Thank you .
Anka

		
____________________________________________________
Sell on Yahoo! Auctions – no fees. Bid on great items. http://auctions.yahoo.com/
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Do you notice that you are creating a new Gtk::Label and placing it into your statusbar each time checkTime is called ? This is what causes your seg fault.

If you simply want to display the current time in your statusBar, the push() and pop() methods do the job. Also, as Jason stated, ctime() adds /n at the end of the string, so you might want to remove it.

--
Yann Normand
Sogeti-Transiciel




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