c++ - Passing QString variables between QDialog forms -
the problem have encountered bit trickier , not similar other problems / solutions on net. provide brief idea of application, work-flow shown below;
i have done till fetching data in dialog2 , saved data in qstring
variables. , want pass dialog1 which open. using these values settext
set values qlabel
, qlineedit
widgets in dialog1.
the technique have used not reflecting changes on dialog1. maybe because open , has not been updated.
relevant code snippets shown below -
dialog1.h
private slots: void on_pushbutton_2_clicked(); //this slot pushbutton open dialog2 public: void setlabeltext(qstring str); //for setting text of label
dialog1.cpp
void dialog1::on_pushbutton_2_clicked() { dialog2 dialog2; dialog2.setmodal(true); dialog2.setwindowflags(qt::framelesswindowhint); dialog2.exec(); } void dialog1::setlabeltext(qstring str) { ui->lineedit->settext(str); qdebug()<<"value arrived "<<str; }
dialog2.h
public slots: void savesettings(); //slot button press @ dialog2, set values @ dialog1 , close dialog2
dialog2.cpp
void dialog2::savesettings() { dialog1 dialog1; dialog1.setlabeltext(vehicle_name); //vehicle_name qstring variable qdebug()<<"sent value "<<vehicle_name; accept(); }
the qstring getting passed between qdialog form classes. have used qdebug() messages verify this.
how ensure values of variables reflected on dialog1 ??? can please guide me reference code ???
dialog2 should provide signal containing data want transfer dialog1 gets emitted whenever dialog2 done action:
dialog1.cpp
void dialog1::on_pushbutton_2_clicked() { dialog2 dialog2; dialog2.setmodal(true); dialog2.setwindowflags(qt::framelesswindowhint); connect(&dialog2, &dialog2::datafetched, this, &dialog1::updatedata); // or qt4 connect syntax // connect(&dialog2, signal(datafetched(const qstring&)), this, slot(updatedata(const qstring&)); // or directly connect label // connect(&dialog2, &dialog2::datafetched, ui->lineedit, &qlineedit::settext); dialog2.exec(); } void dialog1::updatedata(const qstring& data) { ui->lineedit->settext(data); }
dialog2.h
public slots: void savesettings(); //slot button press @ dialog2, set values @ dialog1 , close dialog2 signals: void datafetched(const qstring& data);
dialog2.cpp
void dialog2::savesettings() { // whatever generate data emit datafetched(vehicle_name); accept(); }
Comments
Post a Comment