You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, June 16th 2006, 3:36pm

pass variable between 2 forms

Hello, i'm new in this community, my ask is the next

I'm have two forms, in one the users introduce a date with the class QDateEdit then, the user's click on a push button and he goes to a second form, when the user do click in the first from, the date store pass to second form how to qstring, i'm know transform the control qdate to qstring, but, i don't know how pass the variable that contain the date (qstring) to the second form, how i did this?

daihard

Trainee

  • "daihard" is male

Posts: 86

Location: Lynnwood, WA, USA

Occupation: Senior Software Engineer

  • Send private message

2

Friday, June 16th 2006, 3:46pm

RE: pass variable between 2 forms

Quoted

Originally posted by restiz
Hello, i'm new in this community, my ask is the next

I'm have two forms, in one the users introduce a date with the class QDateEdit then, the user's click on a push button and he goes to a second form, when the user do click in the first from, the date store pass to second form how to qstring, i'm know transform the control qdate to qstring, but, i don't know how pass the variable that contain the date (qstring) to the second form, how i did this?

I assume you call the two forms (or dialogs) from one place in your application, using the "exec()" method. That being the case, you can pass the variable back to the caller and pass it to the second form, as follows:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
void fcn(void) {
    .....
    .....
    if (m_formOne->exec()) {
        QString strData = m_formOne->getMyData(); /* your own method */

        m_formTwo->setMyData(strData); /* your own method */
        if (m_formTwo->exec()) {
            ....
        }
    }
}

Will this work for you?
Registered Linux User: #281828
Tools Development using Qt 3.3.4 and 4.5.2
CentOS 4.7 / KDE 3.5.10

3

Saturday, June 17th 2006, 11:57am

mmm not, the forms are the principals forms of the aplication, when you execute the aplication, the first form on appear is the form on you select the date and in the sencond with the select date, in a table's show the information reference at the day, but i'm don't obtain the form to pass the select date in the first from tu the second form for realise the consult to db.

How i pass the variable to the first from to the second? (the two forms are the forms principal in the application)

drow

Beginner

  • "drow" is male

Posts: 22

Location: Roma ( Italy )

Occupation: programming

  • Send private message

4

Saturday, June 17th 2006, 2:12pm

RE: pass variable between 2 forms

Hi all,
where you create the forms in some method?
if you have both istance at same time, you can try to use a SIGNAL/SLOT.
You must define your personal signal and personal slot.
cna You post some code?

bye
Qt 3.1.2 - O.S RedHat 4 EE

5

Sunday, June 18th 2006, 12:33am

i'm know i create a custom signal/slot, but i don't know how link the slot in the form 1 (this slot turns the objetc qdateedit to qstring)with the form 2, i'm refer, i have a slot with function is return a qstring of qdatetime, this is stored in a variable, how pass this variable to the form 2, where implementing de slot?

toyranm

Trainee

Posts: 71

Location: Turkey

  • Send private message

6

Thursday, June 22nd 2006, 8:30am

Hi,

In which variable you keep the date data. If it is member to your first form, it will be deleted when this form is closed. Here are two ways to keep your data: (I assume that your first form as Form1, second as Form2)

1 - You can use globals which is defined in main. They can be called in your both forms with extern. So you fill them in Form1 and use in Form2.
2 - Create a global object to create Form2. extern it in Form1. When you get the data from QDateEdit, you pass them to the members of the Form2. For example,

Let us assume we create Form2 with the global Form2 object. (Form2 *g_form2). This form should have members QString m_date;

In Form1, when you get the data QDateEdit fill also m_date as follows:
g_form2->m_date = QDateEdit::currentDate().toString("dd.MM.yyyy");

Try this. If you didnt understand, you ask.

7

Thursday, June 22nd 2006, 10:53am

Form1.cpp:

Source code

1
2
3
4
5
...
QString s; // Outside all functions
...
s = "blablabla";
...


Form2.cpp:

Source code

1
2
3
4
5
...
extern QString s;
...
QString s2 = s; // s2 = "blablabla";
...


Hope it helps.