Dargon Dargon - 2 months ago 18
C++ Question

QT - Dialog(modal) with sub functions

firstly I have to apologize for my bad English, I'm still learning the language ;)

Now, my Problem:

I've created a Dialog named form.ui, I've created it via pointer in the main Header:

private:
QDialog *newform;
Ui::Form Form;

private slots:
void slotShowEntry();
void newEntry();


Then I called it in the main Program:

void SoftwareV::slotNewEntry()
{
newform =new QDialog;
newform->setModal(true);
Form.setupUi(newform);
newform->show();

connect(Form.buttonBox_ok_ab, SIGNAL(accepted()), newform, SLOT(newEntry()));
}


Now, I want to get the information the user has written/given into the Dialog with the Subfunction called newEntry(),eg I want to get text from the QLineEdit, but I have no idea how I can connect the Dialog with the subfunction.

I hope somebody can help me with this Problem! thank you!

Answer

There's not quite enough information in your code to be exact, but I think what you're looking for is something like this in your newEntry method:

QString user_text = Form.someLineEdit->text ();

Instead of "someLineEdit", the name of the control is the name you gave it in Qt Designer when you created the form. What you do with the user_text result is up to you. Each control in the form has a unique name, and how you get data out of the control depends on the type of control (QCheckBox, QComboBox, QLineEdit, etc.). Each of those controls has functions for setting and retrieving data. You can look them up in Qt Assistant for complete details.