PDA

View Full Version : How to separate functionality of tab pages from Qt main window class



prady
24th July 2012, 06:21
In my application, I have QTabWidget with 3 pages with controls designed in it, using Qt creator 2.4.1. now I want to separate the functionality of these pages from MainWindow by creating new classes.

My question is how to access the MainWindow::ui instance in my new class ? which is declared in private.

it is a qt-desktop application and platform is qt 4.8.1/win 7.

wysota
24th July 2012, 07:20
Why do you want to access MainWindow ui?

prady
24th July 2012, 12:59
because I want to use the controls of tab pages in new class,.... after searching and from forums I come to know I have to pass ui instance as a parameter to another class where I have to use those controls. but I planned to create different widget ui files and attach it to my main tab widget, I hope this will serve my purpose.

Talei
24th July 2012, 13:18
How passing widget UI to other class differ from accessing UI elements from i.e. MainWindow class? IMHO it's not separating interface but simply putting code in diff. place.

If You want to use UI widgets in/from different class, then I would create separate class with getter/setter approach. Then I would connect appropriate signals from UI to my separate class and pass only information that needs to be passed.

wysota
24th July 2012, 13:21
because I want to use the controls of tab pages in new class,....
That doesn't require you to access MainWindow ui. You instantiate pages and place them in MainWindow and then you access methods of those instances from within MainWindow, not the other way round.

prady
27th July 2012, 07:21
Ok, I was using a single ui file with all the tab pages designed, now I created widgets for tab pages and and accessing the instance of those classes from MainWindow.