PDA

View Full Version : Using variable from dialog in another dialog



Abeer
24th May 2010, 16:04
Hi everyone...
I have variable from type: integer
its name for example num , I defined it in dialog1.h
I stored value in it from user by lineEdit
when user enter value, I change it to int and then store in num variable..

now I need to use this variable in another file
so, I must use it in dialog2.cpp file

I called it like this:
dialog1::num but it doesn't work!

then I did that:

dialog1* d=new dialog1(this);
d->num;

but also it doesn't work!

please can anyone help me?!
I don't have enough time..
I must finish my project today:(

tbscope
24th May 2010, 18:56
There are a few ways to do this. Check on google for some C++ tutorials, this is basic C++.

Here are a few ways:
1. Pass the object of your first dialog to your second, then you can use it to set and get values. I recommend you do this as this is the easiest way
2. Use signals and slots
3. Define a global singleton to store your settings and use the instance to set and get values. This breaks object oriented programming patterns though thus not really recommended.