Use MainWindow ui in another class?
-
How do I use the ui-> property or attribute of MainWindow from another class(class called GetInfo).
Here is the function I want to move to another class:
@void MainWindow::grabDate(){
ui->lblDateChange->setText("August 5, 1940");
}@
I'd like to move it to another class called GetInfo. So I would think it would look like this:
@void GetInfo::grabDate(){
ui->lblDateChange->setText("August 5, 1940");
}@
Its a simple label that I change the text of. I launch it within MainWindow with grabData();
Also, how do you create an object of MainWindow class in another class? Is that even possible.
Can I do this to create object of MainWindow in GetInfo class?:
@MainWindow objMainWindow;@
or
@
MainWindow objMainWindow = new MainWindow;
@
Please help.
Thanks. -
I don't know what is your purpose but I can guess you look for a rapid way to create widgets in your application; then you would not want to touch the Ui::MainWindow as it should manage your ui logic, I mean it should remain created in main.cpp; for widgets creation by designer just add other designer's form providing code for creating widgets having a QWidget's parent
anyway, regarding your code:
bq. Can I do this to create object of MainWindow in GetInfo class?:
MainWindow objMainWindow;
this is enough to create a QMainWindow object in your class but since ui is created in MainWindows class's constructor:
@MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)@and is private, you need a public getter for it in MainWindow
hope this help! :)
Cheers!
-
[quote author="NicuPopescu" date="1381488511"]
this is enough to create a QMainWindow object in your class but since ui is created in MainWindows class's constructor:
@MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)@and is private, you need a public getter for it in MainWindow
hope this help! :)
Cheers![/quote]
What is a public getter?