PDA

View Full Version : Creating and Using Qdialog



tpf80
14th March 2007, 06:18
I have created a modal dialog and it responds to the 'ok' and 'cancel' buttons fine. My main issue is that when I attempt to put code to access the other fields in the dialog I get some errors:



//popup for modal dialog:
void PulseMain::popupmodal() {

//create a dialog box:
DialogLogin dlg(this);


//do something once we click OK:
if( dlg.exec() == QDialog::Accepted ) {

//initialize a place to put our login information:
var_login login;

// Extract the information from the dialog
login.username = dlg.userid->text();
login.password = dlg.password->text();



QMessageBox::warning( this, "Dialog results!", "We clicked OK!");

//else do something when we click cancel:
} else {

QMessageBox::warning( this, "Dialog results!", "We canceled it!");

}




//dlg.exec();

}




everything works fine when the following lines are removed:




login.username = dlg.userid->text();
login.password = dlg.password->text();



when the lines are there I get the following error message when compiling the program:



ui_dialog_login.h:29: error: 'QLineEdit* Ui_DialogLogin::userid' is inaccessible
calculatorform.cpp:48: error: within this context
ui_dialog_login.h:30: error: 'QLineEdit* Ui_DialogLogin::password' is inaccessible
calculatorform.cpp:49: error: within this context


so it seems that I am using the wrong route to access the text items in the dialog. I am sure that its something simple that I am missing that would make this work properly. Anyone have an idea?

vermarajeev
14th March 2007, 06:51
userid;
password;
are declared and defined in UI namespace so probably you have to access them using your UI nampespace or something like that.

Lykurg
14th March 2007, 06:55
are declared and defined in UI namespace so probably you have to access them using your UI nampespace or something like that.

... and it would be better if you had a public function in DialogLogin, which return the login informations in a var_login type. So the elements could stay private and if you change the dialog you just have to alter his own sources.

Lykurg

tpf80
14th March 2007, 07:25
Thanks you both, I accessed the UI namespace with in DialogLogin to get at the information, and then I was able to use a public function within DialogLogin to pass the var_login type to the parent window.

Does this mean that when you click "ok" or "cancel" and the dialog disappears from view, that it still is actually there, just you can't see it? or is it destroyed?

Lykurg
14th March 2007, 10:06
Does this mean that when you click "ok" or "cancel" and the dialog disappears from view, that it still is actually there, just you can't see it?
right,

or is it destroyed?
the dialog is destroyed at the end of the scope. In your case after the finishing brace of PulseMain::popupmodal().


Lykurg