Access the UI, from multiple windows.
-
In what way not working ?
it just returns the pointer to your
Settings_Widget so only way it can fail is to return null.I wonder here
void Window1::on_Button001_clicked()
{MainWindow* B = new MainWindow; << you create new one. ?
so you dont have one already ?
Or is that on purpose ?
So each time you click you make a new window ?@mrjj I have another button to activate and show that window.
MainWindow* B = new MainWindow;
No,i have already one window.
I just use this to get MainWindow method, and try to set checkerBox as true but from ther.If i copy the same code from that button, and paste it to Window1, it's working, but is not the way how it should work, i dont want to set it ther....
I mean:
MainWindow* B = new MainWindow; B->Get_Window_Data()->ui->CheckerBox->setChecked(true); if(B->Get_Window_Data()->ui->Auto_Reset_Data_Timer->isChecked()) { //do something }
When i say "Is not working", i mean when i click the button, checkBox should return true, and when i compare it in another window, checkBox returns false, i think because i set it to another copy... How,i don't know. It should return Settings_Widget in window1.
-
Hi
Im sorry if we frustrated you. We just know from experience
what works bad over time so that is why we seem so keen to do it the right way.
Lets start over.
ok, so you have a normal main.cppint main(int argc, char* argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
so w is mainwindow
and it has the true Settings_Window embedded.So we need Window1 to have access to MainWins Settings_Window and not a new copy.
So Window1 should NOT new one it self but get the one from Mainwin.I assume Mainwindow also creates and show Window1
You can change its constructor to take a Settings_Window * and it can then store it for accessing.Like
#include "Settings_Window.h" // so it knows the TYPE ( make to use right name if not that) class Window1 : public QMainWindow { Q_OBJECT Settings_Window *GivenToMe; public: explicit Window1 (QWidget *parent = 0, Settings_Window *TheTrueOne) { GivenToMe = TheTrueOne; // store the pointer for later } ~Window1 (); .... };
// then in MainWin where you show the Window1 void MainWindow::ShowSettings() { Window1 * Win1= new Window1(this, & S_Window ); // the & to make it pointer Win1->show(); }
now inside
void Window1::SomeButtonClick() {
// you now have GivenToMe that is the Settings_Widget from MainWindow
now you can call public functions in it
if ( GivenToMe -> SomeFunc() ) ...}
If you do not want to create public access functions but go directly via UI you have to make it public
so in Settings_Window.hprivate:
Ui::Settings_Windowui;
must be
public:
Ui::Settings_Windowui;to allow
if ( GivenToMe -> ui->CheckerBox->isChecked() ) ...--
What we tried to make you do was to add public access function in mainwindow
so you would say
if ( GivenToMe ->GetSettingForX() ) ( and it just returns the ui->Checker_01->isChecked() )but if you really not want that, then you can make ui public and the syntax you want is then possible
even if its not best practice/bad idea/design.Hope this helps. :)
-
Hi
Im sorry if we frustrated you. We just know from experience
what works bad over time so that is why we seem so keen to do it the right way.
Lets start over.
ok, so you have a normal main.cppint main(int argc, char* argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
so w is mainwindow
and it has the true Settings_Window embedded.So we need Window1 to have access to MainWins Settings_Window and not a new copy.
So Window1 should NOT new one it self but get the one from Mainwin.I assume Mainwindow also creates and show Window1
You can change its constructor to take a Settings_Window * and it can then store it for accessing.Like
#include "Settings_Window.h" // so it knows the TYPE ( make to use right name if not that) class Window1 : public QMainWindow { Q_OBJECT Settings_Window *GivenToMe; public: explicit Window1 (QWidget *parent = 0, Settings_Window *TheTrueOne) { GivenToMe = TheTrueOne; // store the pointer for later } ~Window1 (); .... };
// then in MainWin where you show the Window1 void MainWindow::ShowSettings() { Window1 * Win1= new Window1(this, & S_Window ); // the & to make it pointer Win1->show(); }
now inside
void Window1::SomeButtonClick() {
// you now have GivenToMe that is the Settings_Widget from MainWindow
now you can call public functions in it
if ( GivenToMe -> SomeFunc() ) ...}
If you do not want to create public access functions but go directly via UI you have to make it public
so in Settings_Window.hprivate:
Ui::Settings_Windowui;
must be
public:
Ui::Settings_Windowui;to allow
if ( GivenToMe -> ui->CheckerBox->isChecked() ) ...--
What we tried to make you do was to add public access function in mainwindow
so you would say
if ( GivenToMe ->GetSettingForX() ) ( and it just returns the ui->Checker_01->isChecked() )but if you really not want that, then you can make ui public and the syntax you want is then possible
even if its not best practice/bad idea/design.Hope this helps. :)
-
Hi
Im sorry if we frustrated you. We just know from experience
what works bad over time so that is why we seem so keen to do it the right way.
Lets start over.
ok, so you have a normal main.cppint main(int argc, char* argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
so w is mainwindow
and it has the true Settings_Window embedded.So we need Window1 to have access to MainWins Settings_Window and not a new copy.
So Window1 should NOT new one it self but get the one from Mainwin.I assume Mainwindow also creates and show Window1
You can change its constructor to take a Settings_Window * and it can then store it for accessing.Like
#include "Settings_Window.h" // so it knows the TYPE ( make to use right name if not that) class Window1 : public QMainWindow { Q_OBJECT Settings_Window *GivenToMe; public: explicit Window1 (QWidget *parent = 0, Settings_Window *TheTrueOne) { GivenToMe = TheTrueOne; // store the pointer for later } ~Window1 (); .... };
// then in MainWin where you show the Window1 void MainWindow::ShowSettings() { Window1 * Win1= new Window1(this, & S_Window ); // the & to make it pointer Win1->show(); }
now inside
void Window1::SomeButtonClick() {
// you now have GivenToMe that is the Settings_Widget from MainWindow
now you can call public functions in it
if ( GivenToMe -> SomeFunc() ) ...}
If you do not want to create public access functions but go directly via UI you have to make it public
so in Settings_Window.hprivate:
Ui::Settings_Windowui;
must be
public:
Ui::Settings_Windowui;to allow
if ( GivenToMe -> ui->CheckerBox->isChecked() ) ...--
What we tried to make you do was to add public access function in mainwindow
so you would say
if ( GivenToMe ->GetSettingForX() ) ( and it just returns the ui->Checker_01->isChecked() )but if you really not want that, then you can make ui public and the syntax you want is then possible
even if its not best practice/bad idea/design.Hope this helps. :)
I have few errors:
default argument missing for parameter 2 of 'Window1::Window1(QWidget*, Settings_Window*)'
explicit Window1(QWidget *parent = 0, Settings_Window *TheTrueOne)
^redefinition of 'Window1::Window1(QWidget*, Settings_Window*)'
Window1::Window1(QWidget *parent, Settings_Window *TheTrueOne = 0) :
^'Window1::Window1(QWidget*, Settings_Window*)' previously defined here
explicit Window1(QWidget *parent = 0, Settings_Window *TheTrueOne)
^Can you correct it? Because i tried what i could, but doesn't help.
Window1.h
#ifndef WINDOW1_H #define WINDOW1_H #include <QWidget> #include "Settings_Window.h" namespace Ui { class Window1; } class Window1 : public QWidget { Q_OBJECT Settings_Window *GivenToMe; public: explicit Window1(QWidget *parent = 0, Settings_Window *TheTrueOne) { GivenToMe = TheTrueOne; // store the pointer for later } ~Window1(); private: Ui::Window1 *ui; }; #endif // WINDOW1_H
And this is Window1.cpp
#include "window1.h" #include "ui_window1.h" #include "settings_window.h" Window1::Window1(QWidget *parent, Settings_Window *TheTrueOne = 0) : QWidget(parent), ui(new Ui::Window1) { ui->setupUi(this); } Window1::~Window1() { delete ui; }
-
Hi,
Default arguments can only be set in the function declaration. So move all
= 0
to the header.As a matter of good practice, the
parent
parameter should always be last. Question of coherency with the Qt library and what other developers expects. -
Hi,
Default arguments can only be set in the function declaration. So move all
= 0
to the header.As a matter of good practice, the
parent
parameter should always be last. Question of coherency with the Qt library and what other developers expects. -
Hi,
Default arguments can only be set in the function declaration. So move all
= 0
to the header.As a matter of good practice, the
parent
parameter should always be last. Question of coherency with the Qt library and what other developers expects. -
Do you have matching declaration and implementation ?
-
Header :
explicit Window1(Settings_Window *TheTrueOne = 0, QWidget *parent = 0) { GivenToMe = TheTrueOne; }
Source:
Window1::Window1(Settings_Window *TheTrueOne,QWidget *parent) : QWidget(parent),ui(new Ui::Window1) { ui->setupUi(this); }
error: redefinition of 'Window1::Window1(Settings_Window*, QWidget*)'
Window1::Window1(Settings_Window *TheTrueOne,QWidget *parent) : QWidget(parent),ui(new Ui::Window1)
^I i remove ther Settings_Window, then i have no type specified error.
-
You wrote the method twice: once in the header and a second time in the implementation file. That's what the compilers is complaining about. You can have only one implementation.
-
You wrote the method twice: once in the header and a second time in the implementation file. That's what the compilers is complaining about. You can have only one implementation.
-
Can someone create just any working example?? I want it to compile it, and see if it's gonna work.
@Loc888 Come on it's simple. Just remove the method definition from the header file:
// Header : explicit Window1(Settings_Window *TheTrueOne = 0, QWidget *parent = 0); // Source: Window1::Window1(Settings_Window *TheTrueOne,QWidget *parent) : QWidget(parent),ui(new Ui::Window1), GivenToMe(TheTrueOne) { ui->setupUi(this); }
Some reading about C++ would help.
-
@Loc888 Come on it's simple. Just remove the method definition from the header file:
// Header : explicit Window1(Settings_Window *TheTrueOne = 0, QWidget *parent = 0); // Source: Window1::Window1(Settings_Window *TheTrueOne,QWidget *parent) : QWidget(parent),ui(new Ui::Window1), GivenToMe(TheTrueOne) { ui->setupUi(this); }
Some reading about C++ would help.
@jsulm I fixed that issue.. I mean, when i change the checkBox in the other window, nothing change, and i try like 50 times and more, and same stuff, doesn't work,and i can't understand why.
My compiler is giving me around 50 warnings, when i create non-static data member, it is normal?
-
@jsulm I fixed that issue.. I mean, when i change the checkBox in the other window, nothing change, and i try like 50 times and more, and same stuff, doesn't work,and i can't understand why.
My compiler is giving me around 50 warnings, when i create non-static data member, it is normal?
-
@Loc888
Hi
Nope 50 warning is not normal.
What does warnings say ?Also, if nothing happens. Are you sure u are not creating a second copy/instance ?
mainwindow.h:41: Warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
Settings_Window* Settings_Widget = new Settings_Window;
^Men, i don't know about that instance.....I send you a simple project, and if you want., you can take a look, i am really tired.
-
mainwindow.h:41: Warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
Settings_Window* Settings_Widget = new Settings_Window;
^Men, i don't know about that instance.....I send you a simple project, and if you want., you can take a look, i am really tired.
@Loc888
Hi
It gives that warning if you doclass xxx : whatever {
int var =0;
}
and not using c++ 11Do you have
Settings_Window* Settings_Widget = new Settings_Window;
in a. h file ?Yes, please. zip project. upload to somewhere and send me link.
-
@Loc888
Hi
It gives that warning if you doclass xxx : whatever {
int var =0;
}
and not using c++ 11Do you have
Settings_Window* Settings_Widget = new Settings_Window;
in a. h file ?Yes, please. zip project. upload to somewhere and send me link.
-
http://www.mediafire.com/file/n9e0d3q02soc3z5/Test_3.rar
Yes, it's in .h file. Correct this stuff if you can, and try to compile, because i do a lot of tries, and i don't really know how it's looks like right now.