Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 8

Qt-interest Archive, March 2002
Maiantaining a variable value throughout the application


Message 1 in thread

Hello all,


	I am having the selected item of combo box in a variable
strLanguage..
I have to pass this variable to the form2. 
I have used the variable as

static char strLanguage[20] in form1.
Then i have used extern char strLanguage in form2.
I displayed this variable in form2 as printf("\n%s",strLanguage)
When i compile the following error is coming.

In function `Form2::Form2(QWidget *, char const *, bool, unsigned int)':
 undefined reference to `strLanguage'

How to refer the variable.

























On Wed, 20 Mar 2002, Mariusz Lotko wrote:

> On Wed 20. March 2002 12:09, you wrote:
> > Hi Konrad,
> >
> > I am not having any interface for both the forms.
> > What i am doing is i am having one application.
> > In this applicaiton, i have defined the form2.
> > Then in form1, whenever the ok button is clicked, in the click event of
> > this button, i am closing the first form and since i have defined form2 in
> > the main appliction, it will be automatically invoked.
> > So i am not having any interface.
> >
> > How can i get the variable as i have said earlier from the combobox to the
> > next form.
> 
> void QComboBox::activated ( int index ) [signal]
> 
> Read the doc about signal/slot mechanism in Qt.
> 
> 

-- 
 [ signature omitted ] 

Message 2 in thread

You are definining your global as 'static' when really it should not be
'static'.  Static in non-member-variables means that it is not exported to
other compilation units, which is why you are getting a link error.

Just remove the keyword static and your variable should be visible from
all compilation units that are interested in it and that have that extern
declaration...

-Calin


On Thu, 21 Mar 2002, A.BalaSaraswathi wrote:

> Hello all,
>
>
> 	I am having the selected item of combo box in a variable
> strLanguage..
> I have to pass this variable to the form2.
> I have used the variable as
>
> static char strLanguage[20] in form1.
> Then i have used extern char strLanguage in form2.
> I displayed this variable in form2 as printf("\n%s",strLanguage)
> When i compile the following error is coming.
>
> In function `Form2::Form2(QWidget *, char const *, bool, unsigned int)':
>  undefined reference to `strLanguage'
>
> How to refer the variable.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On Wed, 20 Mar 2002, Mariusz Lotko wrote:
>
> > On Wed 20. March 2002 12:09, you wrote:
> > > Hi Konrad,
> > >
> > > I am not having any interface for both the forms.
> > > What i am doing is i am having one application.
> > > In this applicaiton, i have defined the form2.
> > > Then in form1, whenever the ok button is clicked, in the click event of
> > > this button, i am closing the first form and since i have defined form2 in
> > > the main appliction, it will be automatically invoked.
> > > So i am not having any interface.
> > >
> > > How can i get the variable as i have said earlier from the combobox to the
> > > next form.
> >
> > void QComboBox::activated ( int index ) [signal]
> >
> > Read the doc about signal/slot mechanism in Qt.
> >
> >
>
>


Message 3 in thread

This is not related to Qt.  You should find a C++ forum to ask your question.

On Wednesday 20 March 2002 11:26 pm, A.BalaSaraswathi wrote:
>
> 	I am having the selected item of combo box in a variable
> strLanguage..
> I have to pass this variable to the form2.
> I have used the variable as
>
> static char strLanguage[20] in form1.

What is form1?  I am assuming that it is a class.  Also, you should likely be 
using a string or a QString instead of the C-style char[].

> Then i have used extern char strLanguage in form2.
> I displayed this variable in form2 as printf("\n%s",strLanguage)
> When i compile the following error is coming.

You should use cout instead of printf().  Also, you should refer to 
strLanguage correctly, i.e. form1::strLanguage, assuming form1 is a class and 
strLanguage is defined inside of it.