PDA

View Full Version : declaration of global variables???



pranav_kavi
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()
{
.....
.....
qDebug(var);
}//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,
Kavitha

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

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

pranav_kavi
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'.
rgards,
kavitha

sunil.thaha
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
http://www.codeguru.com/Cpp/Cpp/cpp_mfc/singletons/article.php/c823/
http://www.steveheller.com/cppad/Output/function8.html

wysota
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.

Mariane
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.

Mariane

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.