declaration of global variables???
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
Re: declaration of global variables???
How do you know that var is empty?
Re: declaration of global variables???
Are you sure this itemDoubleClicked() gets called?
Re: declaration of global variables???
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
Re: declaration of global variables???
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_...icle.php/c823/
http://www.steveheller.com/cppad/Output/function8.html
Re: declaration of global variables???
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.
Re: declaration of global variables???
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.