PDA

View Full Version : Access UI Components from different source files



cevou
13th February 2009, 07:51
The Source File of my Application got really large. Thats why I wanted to split it into multiple files.
I ran into the following problem:
In class A I initialize the UI. But how can I check the state of components (i.e. checkstate of checkbox) from another source file?
class A conntects PushButtons to functions in class B and class B needs to know the checkstates of some components.
Obiously I can't include class A in class B and class B in class A becaue this would lead into a cycle and the program won't compile/start.

I hope someone can help me to solve this Problem.

talk2amulya
13th February 2009, 08:08
well, u r gonna hv to set the 'ui' variable public.. then u can access its different components in different files

cevou
13th February 2009, 08:23
My UI is defined like this

mainwindow.h

#include <QMainWindow>
#include "ui_mainwindow.h"
#include "main_print_functions.h"
class MainWindow : public QMainWindow, public Ui::MainWindow {
Q_OBJECT

public:
MainWindow();
.
.
.
};


So how can I access the components in main_print_functions class?
This doesn't work:

MainWindow gui;
gui.checkBox->isChecked()

Can you post a piece of code that shows me how to do this?

jacek
13th February 2009, 23:44
This doesn't work:

MainWindow gui;
gui.checkBox->isChecked()
It should work. Are you sure that your check box is called "checkBox"?

BTW, it's not a good practice to access GUI components directly from other classes. If you change something in your GUI, you will have to fix code in many places.