How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog
The title pretty much states it all.
I have a modeless dialog in my application, and within it is a QLineEdit object and a QPushButton. How can I emit the value of the QLineEdit object (i.e. the user input) to the rest of the application when the user pressed the QPushButton (i.e. "Ok")?
If it were a modal dialog, then it'd simply be the return value of the calling function, but being modeless... any suggestions?
Re: How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog
Simply emit a signal from the slot connected to the Ok button.
Then in your program connect a slot to this signal.
Re: How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog
Please excuse my ignorance, but I'm not quite following. To keep things simple, here's the code:
Code:
bool MyCanvas::HorizonDialog()
{
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setWindowTitle("New Horizon");
ok->setDefault(true);
connect(ok,SIGNAL(clicked()),dlg,SLOT(close()));
connect(ok,SIGNAL(clicked()),this,SLOT(NewHorizon()));
layout->addWidget(text);
layout->addWidget(ok);
layout->addWidget(cancel);
dlg->setLayout(layout);
dlg->raise();
dlg->show();
return true;
}
Are you suggesting placing a
Code:
connect(ok,SIGNAL(clicked()), //.... I honestly don't know what to connect that signal to.
Re: How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog
tbscope is suggesting to subclass QDialog, move most of the code from your HorizonDialog() method to its constructor and add a signal to the class. Besides the signal add a slot that will be connected to your ok button's clicked signal. From within that slot emit the dialog signal and make it carry the value you want.
Re: How to emit QLineEdit's text after pressing a QPushButton in a modeless QDialog
Ah, yes indeed, that would do the trick, wouldn't it?