View Full Version : declaration of global variables???

12th January 2006, 11:06
Hi friends,

I'm a beginner to Qt and in the current application that I'm developin on Linux,I have encounterd problem in using global variables.
I ve a main.cpp,that has a declaration as follows,
QString var;
int main()
}//end main
In another file-BList.ui.h,I am using the 'var' variable and assigning it a value in one of its member fns.Part of the code is as follows,
extern QString var;
void BList::itemDoubleClicked()
var = "BUDDY";
}//end fn
When I run the project,the value of 'var',it is displayed as nothing...May I know what the problem is???
Any help would be appreciated...

Thanx & Rgards,

12th January 2006, 11:16
How do you know that var is empty?

12th January 2006, 11:23
Are you sure this itemDoubleClicked() gets called?

12th January 2006, 11:31
I'm very sure that the member fn-itemDoubleClicked is being calld as it performs many other operations other than assigning a value to 'var'.

12th January 2006, 12:19
Since you are not getting and Compile time errors ....

I am sure that you are clearing the var else where
or you might be using the variable before the function gets called !

And please avoid using Globals ... Anyone Anywhere can Change it !!!
It is not a good programming practise. Please go through the links

13th January 2006, 11:57
Can you show us the part of code where you display the variable content and a kind of explanation how your application works? Because you didn't really provide any info about the subject, just noted the fact that "it doesn't work". Don't expect people to solve your problems if you don't provide any info which could help them.

31st January 2006, 20:56
If you shoudn't use global variables, how do you pass a variable
(in this case an int **) from a QWidget to a function which is written
in mazeform.ui.h?

In mazeform.ui.h I have the filesave function, which should save the
values of this int **. It is not in an object, it is just in mazeform.ui.h,
which is where the Designer wrote it.

Oh, please, and the other way round too? The fileopen() will need to
send an int ** to the widget.


PS I posted here because I started by looking for global variables or
ways round using them. If I should have started a new post please
tell me.