c++ - How to pass data between preestablished windows in Qt? -


i have wizard class, creates 3 pages in form of qstackedwidget in constructor. each page own class.

in page one, have variety of forms , i've implemented slot assigns them when next button clicked. they're assigned respective variables in wizard class. goal pass information pagetwo class appropriate computations. pointers on how this?

wizard class

class wizard : public qdialog {     q_object public:      wizard();     qstring nameinput;     etc } 

constructor

wizard::wizard() : qdialog() {     pages = new qstackedwidget();     pages->addwidget(pageone = new pageone(pages));     pages->addwidget(pagetwo = new pagetwo(pages));     connect(next, signal(clicked(bool)), this, slot(saveforminfo())); } 

assignment function

void wizard::saveforminfo() {     nameinput = pageone->nameedit->text();     etc } 

pagetwo class

class pagetwo : public qwidget { public:     pagetwo(qwidget *parent = 0);     void displayoutput(qhboxlayout *layout); } 

is right way going doing this? first gui project , can't seem figure out how pass variables in, i'm assuming because page created before data passed

there many ways it. without changing code, there suggestion below.

wizard class

class wizard : public qdialog {     q_object public:      wizard();     qstring nameinput;     etc }  wizard::wizard() : qdialog() {     pages = new qstackedwidget();     pages->addwidget(pageone = new pageone(pages, this));     pages->addwidget(pagetwo = new pagetwo(pages, this));     connect(next, signal(clicked(bool)), this, slot(saveforminfo())); }  void wizard::saveforminfo() {     nameinput = pageone->nameedit->text();     etc } 

on pagetwo.h

class wizard;  class pagetwo : public qwidget { public:     pagetwo(qwidget *parent = 0, wizard * wizard);     void displayoutput(qhboxlayout *layout);  private:     wizard * wizard; } 

on pagetwo.cpp

#include <wizard.h>  pagetwo::pagetwo(qwidget * parent, wizard * w) :     qwidget(parent), wizard(w) { } 

then can use this->wizard->nameinput value want on pagetwo


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -