c++ - Sending QStringList between classes using signals and slots -
i have gui built using qt creator. @ point dialog window opened need send variable of type qstringlist. using signals , slots method. however, variable empty once sent. here code samples:
widget.h
class widget : public qwidget { q_object public: explicit widget(qwidget *parent = 0); ~widget(); signals: void mysignal(qstringlist); };
widget.cpp
widget::widget(qwidget *parent) : qwidget(parent), ui(new ui::widget) { // blah blah } widget::~widget() { delete ui; } void widget::on_pushbutton_4_clicked() { qstringlist dlist; int damount = ui->listwidget->count(); for(int i=0; < damount; i++){ dlist << ui->listwidget->item(i)->text(); qdebug() << dlist; } emit mysignal(dlist); mysaver mdialog; mdialog.setmodal(true); mdialog.exec(); }
mysaver.h (the dialog box)
class mysaver : public qdialog { q_object public: explicit mysaver(qwidget *parent = 0); ~mysaver(); public slots: void myreciever(qstringlist); }
mysaver.cpp
void mysaver::myreciever(qstringlist alist) { qdebug << alist; }
main.cpp
int main(int argc, char *argv[]) { qapplication a(argc, argv); widget w; widget *duff = new widget; mysaver *buff = new mysaver; qobject::connect(duff,signal(mysignal(qstringlist)),buff,slot(myreciever(qstringlist))); w.show(); return a.exec(); }
i'd appreciate on this. note: if i'm doing whole method wrong , should doing entirely different tell me!
you creating 2 mysaver
instances , connecting first (invisible) one:
// in main.cpp mysaver *buff = new mysaver; // in widget::on_pushbutton_4_clicked() mysaver mdialog; mdialog.setmodal(true); mdialog.exec();
mdialog
not mysaver
instance connected to.
Comments
Post a Comment