Access UI Components from different source files
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.
Re: Access UI Components from different source files
well, u r gonna hv to set the 'ui' variable public.. then u can access its different components in different files
Re: Access UI Components from different source files
My UI is defined like this
mainwindow.h
Code:
#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:
Code:
MainWindow gui;
gui.checkBox->isChecked()
Can you post a piece of code that shows me how to do this?
Re: Access UI Components from different source files
Quote:
Originally Posted by
cevou
This doesn't work:
Code:
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.