You cannot directly declare something to be "global", but the next best thing is probably to declare something as public in your AppUI class because the one AppUI object of your application is "visible" from everywhere.
HI,
U just declare the variables in appui class's public part.then u access anywhere in following manner
((CExampleAppUi*)(CCoeEnv::Static()->AppUi()))->variablename;
Thanks
mitu
You do it just as you usually do in C and C++
Just define it in the global namespace, or as a public static member variable, and make sure everything that uses it has access to a header file declaration of it.
Though, usage of global variables has some overhead (mostly memory I think) and must be carefully considered on symbian platform, and should only be used when they _really_ are needed.
Which more or less only is when porting code that relies on it.
I don't think that there is any need for that extern const definition in SMSAPPUI_h. Because you include SmsOperations.h, that constant is already defined, and that's all that is needed.
1.error: `KMaxSMSTextLength' was not declared in this scope
2.error: ISO C++ forbids declaration of `iSmsBody' with no type
3.error: template argument 1 is invalid sms/inc smsAppUi.h
1.error: `KMaxSMSTextLength' was not declared in this scope
2.error: ISO C++ forbids declaration of `iSmsBody' with no type
3.error: template argument 1 is invalid sms/inc smsAppUi.h
Hey, come on, since when do I need to mess around with "extern" for declaring a simple, harmless constant in one .h and then using it in a second .h?
Chinu, are you sure you just only deleted the second declaration of KMaxSMSTextLength, changed nothing else and did not produce any typo? If yes, I don't understand the new errors, frankly.
1.error: `KMaxSMSTextLength' was not declared in this scope
2.error: ISO C++ forbids declaration of `iSmsBody' with no type
3.error: template argument 1 is invalid sms/inc smsAppUi.h
Sorry this message was automatically printed.Dont know how...I have not yet viewed any of the posts.
Is there something wrong with my forum user ID?
Actually I had tried with this before making a post.
-------------------------------------------------------------------------------
NOW
-------------------------------------------------------------------------------
I tried with somewhat different approach:----
The errors related to declaration of TInt KMaxSMSTextLength were solved, but
I had following errors:---
error: ISO C++ forbids declaration of `iSmsBody' with no type
error: non-constant `KMaxSMSTextLength' cannot be used as template argument
of course I dont know anything about
GLREF_D
GLDEF_D
LOCAL_D
GLREF_C
GLDEF_C
LOCAL_C
You can just use the global variable as you use it in C and C++.
you need to add this line in the mmp file of your "EPOCALLOWDLLDATA" this enable you to have aritable static data.
make sure you dont have more than 64kb of static data
Forum posts: 1132
You cannot directly declare something to be "global", but the next best thing is probably to declare something as public in your AppUI class because the one AppUI object of your application is "visible" from everywhere.
See also e.g. this earlier thread:
http://www.newlc.com/forum/transmitting-data-between-views
René Brunner
Forum posts: 55
HI,
U just declare the variables in appui class's public part.then u access anywhere in following manner
((CExampleAppUi*)(CCoeEnv::Static()->AppUi()))->variablename;
Thanks
mitu
Forum posts: 1151
You can declare something to be "just global".
You do it just as you usually do in C and C++
Just define it in the global namespace, or as a public static member variable, and make sure everything that uses it has access to a header file declaration of it.
Though, usage of global variables has some overhead (mostly memory I think) and must be carefully considered on symbian platform, and should only be used when they _really_ are needed.
Which more or less only is when porting code that relies on it.
Forum posts: 37
Hi,
I have the following problem.
have 2 classes smsAppUi, SMSOPERATIONS
I need to know how to declare the variable
const TInt KMaxSMSTextLength=100;
SMSOPERATIONS_H
---------------------------------
#ifndef SMSOPERATIONS_H
#define SMSOPERATIONS_H
#include "smsAppView.h"
#include "smsAppUi.h"
class CsmsAppUi;
const TInt KBfrLength= 20;
const TInt KMaxSMSTextLength=100;
class CSmsOperations : public CActive,public MMsvSessionObserver
{
---------------
-------------------
private:
CsmsAppView* iAppView;
CsmsAppUi* iAppUi;
TBufC< KMaxSMSTextLength> iSmsBody;
};
#endif // SMSOPERATIONS_H
SMSAPPUI_h
-------------------------
#ifndef __SMSAPPUI_h__
#define __SMSAPPUI_h__
// INCLUDES
#include "SmsOperations.h"
// FORWARD DECLARATIONS
class CsmsAppView;
class CSmsOperations;
//const TInt KBfrLength= 20;
extern const TInt KMaxSMSTextLength=100;
class CsmsAppUi : public CAknAppUi
{
-------------------
------------------------------
private: // Data
CsmsAppView* iAppView;
CSmsOperations* iOperns;
TBufC< KMaxSMSTextLength> iSmsBody;
};
#endif // __SMSAPPUI_h__
// End of File
At present it is giving 2 errors
1.error: `const TInt KMaxSMSTextLength' previously defined here
2.error: redefinition of `const TInt KMaxSMSTextLength'
Forum posts: 1132
I don't think that there is any need for that extern const definition in SMSAPPUI_h. Because you include SmsOperations.h, that constant is already defined, and that's all that is needed.
So just delete the line
extern const TInt KMaxSMSTextLength=100;René Brunner
Forum posts: 14
Remove "const TInt KMaxSMSTextLength=100"from SmsOperations.h or your AppUi
Forum posts: 37
Then it gives 3 errors
1.error: `KMaxSMSTextLength' was not declared in this scope
2.error: ISO C++ forbids declaration of `iSmsBody' with no type
3.error: template argument 1 is invalid sms/inc smsAppUi.h
Forum posts: 37
Then it gives 3 errors
1.error: `KMaxSMSTextLength' was not declared in this scope
2.error: ISO C++ forbids declaration of `iSmsBody' with no type
3.error: template argument 1 is invalid sms/inc smsAppUi.h
Forum posts: 95
Hi,
Define the variable in .cpp file as global and refer to it in other files as extern.
i.e; in .cpp file
const TInt KMaxSMSTextLength=100;#include ""
.....
....
and in .h file refer it as
#ifndef __SMSAPPUI_h__
#define __SMSAPPUI_h__
// INCLUDES
#include "SmsOperations.h"
// FORWARD DECLARATIONS
class CsmsAppView;
class CSmsOperations;
//const TInt KBfrLength= 20;
extern const TInt KMaxSMSTextLength=100;
class CsmsAppUi : public CAknAppUi
{
-------------------
------------------------------
private: // Data
CsmsAppView* iAppView;
CSmsOperations* iOperns;
TBufC< KMaxSMSTextLength> iSmsBody;
};
#endif // __SMSAPPUI_h__
Chao,
Raghav
Forum posts: 1132
Hey, come on, since when do I need to mess around with "extern" for declaring a simple, harmless constant in one .h and then using it in a second .h?
Chinu, are you sure you just only deleted the second declaration of KMaxSMSTextLength, changed nothing else and did not produce any typo? If yes, I don't understand the new errors, frankly.
René Brunner
Forum posts: 37
Then it gives 3 errors
1.error: `KMaxSMSTextLength' was not declared in this scope
2.error: ISO C++ forbids declaration of `iSmsBody' with no type
3.error: template argument 1 is invalid sms/inc smsAppUi.h
Sorry this message was automatically printed.Dont know how...I have not yet viewed any of the posts.
Is there something wrong with my forum user ID?
Forum posts: 37
yes, I deleted from only one of the classes.
Actually I had tried with this before making a post.
-------------------------------------------------------------------------------
NOW
-------------------------------------------------------------------------------
I tried with somewhat different approach:----
smsappui.h
----------------------
#ifndef __SMSAPPUI_h__
#define __SMSAPPUI_h__
GLREF_C const TInt KMaxSMSTextLength;
----
---
others remaining the same..
The errors related to declaration of TInt KMaxSMSTextLength were solved, but
I had following errors:---
error: ISO C++ forbids declaration of `iSmsBody' with no type
error: non-constant `KMaxSMSTextLength' cannot be used as template argument
of course I dont know anything about
GLREF_D
GLDEF_D
LOCAL_D
GLREF_C
GLDEF_C
LOCAL_C
Now what to do?
Forum posts: 981
The solution for your problem is as alh said:
"You do it just as you usually do in C and C++".....
pirosl
Forum posts: 25
Hi Chinu
You can just use the global variable as you use it in C and C++.
you need to add this line in the mmp file of your "EPOCALLOWDLLDATA" this enable you to have aritable static data.
make sure you dont have more than 64kb of static data