LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-09-2011, 03:38 PM   #1
axd
LQ Newbie
 
Registered: Feb 2011
Posts: 2

Rep: Reputation: 0
interface not responding in glade 3 / gtk with C


Hi,

I am a fairly new ubuntu user. I am using ubuntu 10.04 and glade 3 for building a simple interface that uses C .

In my interface , I have created two buttons : start and stop .Tofocus on my actual problem , I have created a simpler UI and code .

start button runs a while(1) loop and stop should stop the loop .

The problem is , when I press start , the gui freezes and I cannot press any other button . I cant even close my app.After some thorough experimentation, I found out that when I press start , it never comes out of the while loop .

I need the loop to keep running until I press stop . What should i do ?

Here are the functions for the clickable buttons :

Code:
void
on_start_button_clicked (GtkButton *button, gpointer user_data)
{

	flag1=0;
	
	while(1)
	{

		printf("**********checking !!!! ********\n\n");
		
		if(flag1 == 1) 
				break;
	}
}


void
on_stop_button_clicked (GtkButton *button, gpointer user_data)
{
 
        flag1=1; 	

}
 
Old 02-10-2011, 08:32 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
^ i dont know about the freezing issue (try putting in something like sleep(1); after the pprintf()) but the flag1 variable is not global.
what that means is that on_start_button_clicked's flag1 is not the same as on_stop_button_clicked's flag1.
 
Old 02-10-2011, 09:02 AM   #3
axd
LQ Newbie
 
Registered: Feb 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by schneidz View Post
^ i dont know about the freezing issue (try putting in something like sleep(1); after the pprintf()) but the flag1 variable is not global.
what that means is that on_start_button_clicked's flag1 is not the same as on_stop_button_clicked's flag1.
Thanks for the reply schneidz .

The flag1 variable is in fact global . When i click stop before I click start , the loop runs once and exits (that would only happen if the value of flag1 changed to 1 before i pressed start).

I also tried putting sleep() , but the loop would only free up my gui on its exit condition being satisfied.

If I replace the while(1) with :

Code:
int c=0;

while(c<100)
{

  printf("*********checking!!!!*******");
  
  if(flag1==1) break;
  c++;

}

the app would still run through the whole while loop ... I cannot press any other button till then .
 
Old 02-10-2011, 12:09 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by axd View Post
The flag1 variable is in fact global . When i click stop before I click start , the loop runs once and exits (that would only happen if the value of flag1 changed to 1 before i pressed start)...
i find it weird that on_start_button_clicked sets flag1=0 before the while loop so it should never break out of the while.

maybe stepping thru the program in gdb mite help ?

edit: i dont think it is good programming behaviour to use breaks;

maybe something like this would be better:
Code:
void on_start_button_clicked (GtkButton *button, gpointer user_data)
{
	bool flag1=0;
	while(flag1 == 0)
	{
		printf("**********checking !!!! ********flag1 = %b\n\n",flag1);
	}
}
is it possible on_start_button_clicked could return a pointer of a bool instead of a void ?

Last edited by schneidz; 02-10-2011 at 12:15 PM.
 
  


Reply



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
QT, Glade, GTK koolkarthikeyan Linux - General 1 10-16-2006 03:17 AM
GTK+ Glade shandy^^^ Programming 1 02-11-2006 11:42 PM
GTK+(GLADE interface designer) santhosh.linux Programming 3 01-02-2006 12:42 PM
Glade / GTK 2.4 Kane635 Linux - Software 0 09-07-2004 07:53 PM
glade/gtk tutorials for firewall interface Fatz Linux - Security 1 08-08-2004 01:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:07 AM.

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