c++ - Pass opened window instance as parameter into second window -


for example: have 2 windows (a , b). 1 instance of opened combo-box (loaded items in database). click on button "edit" , window b opens allowing me edit contents of mentioned database. need window automatically refresh content when press "save" in window b or when close window b.

all code think of:

a.cpp

b *new_window = new b; b->show(); b->passwindowfunction(this); 

b.cpp

void b::passwindowfunction(sometypeidkwht window) {     window->combobox... } 

as header files, dont know declare.

the signals / slots system of qt provides need here. can this: -

class qwindowa : public qwindow {     q_object      private slots:         void refreshcontent(); // refreshes content of window };    class qwindowb : public qwindow {     q_object      public:         void save(); // save content , emit saved() signal      signals:         void saved(); }; 

as can see, windowa declares slot function called when needs update , windowb has signal saved().

you need connect signal of saved slot refreshcontent() :-

// assuming instances wina , winb have been created connect(winb, &windowb::saved, wina, &windowa::refreshcontent); // using qt 5 connect call 

in save() function of windowb, when you've finished saving content emit saved() signal: -

emit saved(); 

due previous connect call, windowa update content.

as closing window, if delete windowb when gets closed, emit saved() signal in destructor of windowb windowa updated, else handle close event: -

void windowb::closeevent(qcloseevent *event) {     emit saved();     qwindow::closeevent(event); } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -