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, August 4th 2006, 6:16pm

Confirmation dialogs

I'm not very familiar with the way QT handles all of its windows and stuff, other than using ->show() to bring up other windows.

well, now I need to do one of those "Did you wish to do that" dialogs... so I know I can make a function in it where I could pass it some arguments to make the dialog say what i wanted it to say, something like:

dialog->set_text(myString);
dialog->show();

but then when it pops up and has the two buttons, "continue" or "cancel", and the person can click them, how do I return what they clicked? I mean, how does my main class, the parent, know what the person did in the child?

I don't have a good understanding of the slots and signals stuff in QT, and I'm kind of assuming that's what we'd use... but I don't know...

your help is greatly appreciated!! thanks for takin the time!
-Andy

roleroz

Trainee

  • "roleroz" is male

Posts: 67

Location: Santiago, Chile

  • Send private message

2

Friday, August 4th 2006, 6:23pm

RE: Confirmation dialogs

Use QMessageBox, it has some static functions to make things like that

3

Friday, August 4th 2006, 7:16pm

awesome thats perfect

i still dont understand that class though... like the format of the constructor...

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    switch( QMessageBox::information( this, "Qt Application Example",
                                      "The document has been changed since "
                                      "the last save.",
                                      "Save Now", "Cancel", "Leave Anyway",
                                      0, 1 ) ) {
    case 0:
        save();
        ce->accept();
        break;
    case 1:
    default: // just for sanity
        ce->ignore();
        break;
    case 2:
        ce->accept();
        break;
    }


So I see that its (parent, caption, text, button, button, button, ? , ? )
but you can see that the 0,1 i don't understand???? im guessing the defaults? so 0 is what happens if they hit enter and 1 is what happens if they hit esc?

roleroz

Trainee

  • "roleroz" is male

Posts: 67

Location: Santiago, Chile

  • Send private message

4

Friday, August 4th 2006, 7:28pm

check the constructors

int question ( QWidget * parent, const QString & caption, const QString & text, int button0, int button1 = 0, int button2 = 0 )

button0, button1 and button2 should take values from the corresponding enum

5

Friday, August 4th 2006, 7:36pm

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    if ( rows.exist() )
    {
	switch  (	QMessageBox::warning(
		this, "Overwrite map?",
		"A sensor map already exists for this user id.\n"
		"If you continue, that map will be erased and the new map will be uploaded.\n"
		"Continue?",
		"&Yes", "&No", QString::null, 1, 1 )  )
	{  
	case 0:
	    overwrite();
	    break;
	default:
	    break;
	}
    }


does that look good?

roleroz

Trainee

  • "roleroz" is male

Posts: 67

Location: Santiago, Chile

  • Send private message

6

Friday, August 4th 2006, 7:43pm

What's your problem???, stick to the function declaration, 2 strings, 3 ints, no 5 strings and 2 ints

Besides this, use the enums, not fixed values, the enums can change

7

Friday, August 4th 2006, 7:51pm

well i didnt think it was technically 5 strings... since there is only one comma. I saw an example that did it like this:

http://doc.trolltech.com/3.3/qaction-app…mple.html#x1176

so... yea i thought that would be ok,,,,,,,,,,

and what do you mean enums? (i dont know what enums are...?? sorry im stoopid :-/ )

roleroz

Trainee

  • "roleroz" is male

Posts: 67

Location: Santiago, Chile

  • Send private message

8

Friday, August 4th 2006, 7:58pm

if(QMessageBox::question(this, tr("Eliminacion de mensaje"), tr("¿Está seguro que desea eliminar el mensaje?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton) == QMessageBox::Yes)

roleroz

Trainee

  • "roleroz" is male

Posts: 67

Location: Santiago, Chile

  • Send private message

9

Friday, August 4th 2006, 7:59pm

Don't just check the function declaration, in the detailed documentation of the functions there's all this information (including enum values)