Qt-interest Archive, March 2002
Re: How to maintain one variable value throughout the applicaiton
Message 1 in thread
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.
On Wed, 20 Mar 2002, Konrad Neitzel wrote:
> Hi Saraswathi!
>
> > I am having two Qdialogs as form1 and form2.
> > In form1, i am having one combobox and one ok button.
> > I am selecting an item in combobox and maintaing it in one
> > variable.Depending upon the item selected in that combobox,
> > when i click the ok button, that variable value should be
> > maintained in the form2. How to do it.
>
> Maybe you should read more about c++ and the way you program with it!
>
> Normal way:
>
> You have to Forms: MyFormA and MyFormB.
> Maybe you have some Interface: MyFormAInterface. This is just an
> abstract Class that tells me, what additional Functions are available.
>
> MyFormB inherits from MyFormBInterface
> MyFormA inherits from MyFormAInterface
> MyFormAInterface inherits from QWidget.
> MyFormBInterface inherits from QWidget.
>
> MyFormAInterface just tells you, that there is a function that tells
> me, where FormB is found!
>
> void MyFormAInterface::setMyFormBInterface(MyFormBInterface *form) {
> formb = *from;
> }
>
> (And of cource you have a variable, where *form ist stored!)
> MyFormBInterface *formb;
>
> And FormB Also need a Function, that should be called from Form A!
>
> MyFormBInterface::someAction(...);
>
> If you create all the functions you could do something like that:
>
> MyFormA *a = new MyFormA;
> MyFormB *b = new MyFormB;
> a->setMyFormBInterface(b);
> a->show();
> b->show();
>
> And in FormA you could have an action like:
> formb->someAction(...);
>
>
> (Of course you can use MyFormA and MyFormB directly and must not use
> some Interface classes, but a lot of (for example UML based) software
> engeenering works with these interface classes! (Because all you need
> is that interface and nothing more! The interface must not be derivered
> form QWidget, because C++ also can do multiple inheritation!)
>
> With kind regards,
>
> Konrad Neitzel
>
> --
> SoftMediaTec GmbH
> Tel: 0172 / 689 31 45
> Fax: 069 / 90 50 99 53
>
--
[ signature omitted ]
Message 2 in thread
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 3 in thread
Hello Lotko,
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 4 in thread
Hello,
> 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.
static variables have internal linkage. So declare strLanguage without
"static specifier".
Regards
Ilir
--
[ signature omitted ]
Message 5 in thread
"A.BalaSaraswathi" <saraswathi@lantana.tenet.res.in> wrote:
Ok - first point is:
If I write an eMail to you and not to the list please do not reply to
the list again.
> 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.
I know, that you didn't have any interface classes. But you should
build them. or just use the created classes as an interface!
Or just do it simple:
- Create a public function in form2 like "setValue(..)"
- Create a public function "getForm2" in your Application!
On "OK" KLick just call getForm2() from the Application. If the result
is not NULL, call setValue(...).
Or - if you want to develop good software - try to read some stuff
about software engeenering and use Interfaces and so on!
With kind regards,
Konrad Neitzel
--
[ signature omitted ]