Using Stacked Widgets
-
wrote on 15 Feb 2023, 09:13 last edited by
I recently created a Post about an application that I have to make with many interfaces.
As the number of interfaces is important I decided to separate my files (cpp and h) according to the interfaces.I had opted for a solution that was not ideal and @jsulm and @JonB therefore advised me to use "Stacked Widgets".
So I searched and found some information, but very few refer to "Stacked Widgets" and a "Menu" (in a Main Window).
But I finally managed to create a project with what I need.But is it correct...?
Is the structure with file separation correct...?
And if so, how could I modify a member present in my main window from an interface...? (example with "stringTest")main.cpp
#include<QApplication> #include"MyMainWindow.h" int main(int nbArg, char* listeArg[]) { QApplication myApp(nbArg,listeArg); MyMainWindow myWindow; myWindow.show(); myApp.exec(); }
MyMainWindow.cpp
#include"MyMainWindow.h" MyMainWindow::MyMainWindow() { setWindowTitle("Stacked Widgets"); setMinimumHeight(600); setMinimumWidth(600); m_actionQuit = new QAction("Quit",this); m_actionInterfaceA = new QAction("Interface A",this); m_actionInterfaceB = new QAction("Interface B",this); m_actionInterfaceC = new QAction("Interface C",this); m_menuFile = menuBar()->addMenu("File"); m_menuFile->addAction(m_actionInterfaceA); m_menuFile->addAction(m_actionInterfaceB); m_menuFile->addAction(m_actionInterfaceC); m_menuFile->addAction(m_actionQuit); // Definition of Widget Central centralZone = new QWidget; // Definitions of the Different Widgets widgetHome = new Home; widgetHome->setObjectName("home"); widgetInterfaceA = new InterfaceA; widgetInterfaceA->setObjectName("interfaceA"); widgetInterfaceB = new InterfaceB; widgetInterfaceB->setObjectName("interfaceB"); widgetInterfaceC = new InterfaceC; widgetInterfaceC->setObjectName("interfaceC"); // Definition of Stacked Widget m_stackedWidget = new QStackedWidget(centralZone); m_stackedWidget->setMinimumHeight(minimumHeight()); m_stackedWidget->setMinimumWidth(minimumWidth()); m_stackedWidget->addWidget(widgetHome); m_stackedWidget->addWidget(widgetInterfaceA); m_stackedWidget->addWidget(widgetInterfaceB); m_stackedWidget->addWidget(widgetInterfaceC); // Creation Layout and Placement QVBoxLayout *layoutCentralZone = new QVBoxLayout; centralZone->setLayout(layoutCentralZone); setCentralWidget(centralZone); // Creation Connection Signal / Slot connect(m_actionQuit,SIGNAL(triggered(bool)),qApp,SLOT(quit())); connect(m_actionInterfaceA,SIGNAL(triggered(bool)),this,SLOT(showInterfaceA())); connect(m_actionInterfaceB,SIGNAL(triggered(bool)),this,SLOT(showInterfaceB())); connect(m_actionInterfaceC,SIGNAL(triggered(bool)),this,SLOT(showInterfaceC())); } void MyMainWindow::showInterfaceA(){ m_stackedWidget->setCurrentIndex(m_stackedWidget->indexOf(widgetInterfaceA)); } void MyMainWindow::showInterfaceB() { m_stackedWidget->setCurrentIndex(m_stackedWidget->indexOf(widgetInterfaceB)); } void MyMainWindow::showInterfaceC() { m_stackedWidget->setCurrentIndex(m_stackedWidget->indexOf(widgetInterfaceC)); }
MyMainWindow.h
#ifndef MYMAINWINDOW_H #define MYMAINWINDOW_H #include<QtWidgets> #include"Home.h" #include"InterfaceA.h" #include"InterfaceB.h" #include"InterfaceC.h" class MyMainWindow : public QMainWindow { Q_OBJECT public: MyMainWindow(); QString m_stringTest = "ABCDEF"; public slots: void showInterfaceA(); void showInterfaceB(); void showInterfaceC(); private: QMenu *m_menuFile; QAction *m_actionInterfaceA; QAction *m_actionInterfaceB; QAction *m_actionInterfaceC; QAction *m_actionQuit; QWidget *centralZone; QStackedWidget *m_stackedWidget; Home *widgetHome; InterfaceA *widgetInterfaceA; InterfaceB *widgetInterfaceB; InterfaceC *widgetInterfaceC; }; #endif // MYMAINWINDOW_H
Home.cpp
#include"Home.h" Home::Home() { // Initialization QGridLayout *layoutPage; layoutPage = new QGridLayout(); layoutPage->setAlignment(Qt::AlignCenter); layoutPage->addWidget(new QLabel("Accueil")); // Definition of the "Layout" of the "Widget" setLayout(layoutPage); }
Home.h
#ifndef HOME_H #define HOME_H #include<QtWidgets> class Home : public QWidget { public: Home(); private: }; #endif // HOME_H
InterfaceA.cpp
#include"InterfaceA.h" InterfaceA::InterfaceA() { // Initialization QGridLayout *layoutPage; layoutPage = new QGridLayout(); layoutPage->setAlignment(Qt::AlignCenter); layoutPage->addWidget(new QLabel("Interface A")); // Definition of the "Layout" of the "Widget" setLayout(layoutPage); }
InterfaceA.h
#ifndef INTERFACEA_H #define INTERFACEA_H #include<QtWidgets> class InterfaceA : public QWidget { public: InterfaceA(); private: }; #endif // INTERFACEA_H
The complete example is visible on gitHub at this adress :
https://github.com/JuanDeDironne/qt_example_stacked_widgets -
I recently created a Post about an application that I have to make with many interfaces.
As the number of interfaces is important I decided to separate my files (cpp and h) according to the interfaces.I had opted for a solution that was not ideal and @jsulm and @JonB therefore advised me to use "Stacked Widgets".
So I searched and found some information, but very few refer to "Stacked Widgets" and a "Menu" (in a Main Window).
But I finally managed to create a project with what I need.But is it correct...?
Is the structure with file separation correct...?
And if so, how could I modify a member present in my main window from an interface...? (example with "stringTest")main.cpp
#include<QApplication> #include"MyMainWindow.h" int main(int nbArg, char* listeArg[]) { QApplication myApp(nbArg,listeArg); MyMainWindow myWindow; myWindow.show(); myApp.exec(); }
MyMainWindow.cpp
#include"MyMainWindow.h" MyMainWindow::MyMainWindow() { setWindowTitle("Stacked Widgets"); setMinimumHeight(600); setMinimumWidth(600); m_actionQuit = new QAction("Quit",this); m_actionInterfaceA = new QAction("Interface A",this); m_actionInterfaceB = new QAction("Interface B",this); m_actionInterfaceC = new QAction("Interface C",this); m_menuFile = menuBar()->addMenu("File"); m_menuFile->addAction(m_actionInterfaceA); m_menuFile->addAction(m_actionInterfaceB); m_menuFile->addAction(m_actionInterfaceC); m_menuFile->addAction(m_actionQuit); // Definition of Widget Central centralZone = new QWidget; // Definitions of the Different Widgets widgetHome = new Home; widgetHome->setObjectName("home"); widgetInterfaceA = new InterfaceA; widgetInterfaceA->setObjectName("interfaceA"); widgetInterfaceB = new InterfaceB; widgetInterfaceB->setObjectName("interfaceB"); widgetInterfaceC = new InterfaceC; widgetInterfaceC->setObjectName("interfaceC"); // Definition of Stacked Widget m_stackedWidget = new QStackedWidget(centralZone); m_stackedWidget->setMinimumHeight(minimumHeight()); m_stackedWidget->setMinimumWidth(minimumWidth()); m_stackedWidget->addWidget(widgetHome); m_stackedWidget->addWidget(widgetInterfaceA); m_stackedWidget->addWidget(widgetInterfaceB); m_stackedWidget->addWidget(widgetInterfaceC); // Creation Layout and Placement QVBoxLayout *layoutCentralZone = new QVBoxLayout; centralZone->setLayout(layoutCentralZone); setCentralWidget(centralZone); // Creation Connection Signal / Slot connect(m_actionQuit,SIGNAL(triggered(bool)),qApp,SLOT(quit())); connect(m_actionInterfaceA,SIGNAL(triggered(bool)),this,SLOT(showInterfaceA())); connect(m_actionInterfaceB,SIGNAL(triggered(bool)),this,SLOT(showInterfaceB())); connect(m_actionInterfaceC,SIGNAL(triggered(bool)),this,SLOT(showInterfaceC())); } void MyMainWindow::showInterfaceA(){ m_stackedWidget->setCurrentIndex(m_stackedWidget->indexOf(widgetInterfaceA)); } void MyMainWindow::showInterfaceB() { m_stackedWidget->setCurrentIndex(m_stackedWidget->indexOf(widgetInterfaceB)); } void MyMainWindow::showInterfaceC() { m_stackedWidget->setCurrentIndex(m_stackedWidget->indexOf(widgetInterfaceC)); }
MyMainWindow.h
#ifndef MYMAINWINDOW_H #define MYMAINWINDOW_H #include<QtWidgets> #include"Home.h" #include"InterfaceA.h" #include"InterfaceB.h" #include"InterfaceC.h" class MyMainWindow : public QMainWindow { Q_OBJECT public: MyMainWindow(); QString m_stringTest = "ABCDEF"; public slots: void showInterfaceA(); void showInterfaceB(); void showInterfaceC(); private: QMenu *m_menuFile; QAction *m_actionInterfaceA; QAction *m_actionInterfaceB; QAction *m_actionInterfaceC; QAction *m_actionQuit; QWidget *centralZone; QStackedWidget *m_stackedWidget; Home *widgetHome; InterfaceA *widgetInterfaceA; InterfaceB *widgetInterfaceB; InterfaceC *widgetInterfaceC; }; #endif // MYMAINWINDOW_H
Home.cpp
#include"Home.h" Home::Home() { // Initialization QGridLayout *layoutPage; layoutPage = new QGridLayout(); layoutPage->setAlignment(Qt::AlignCenter); layoutPage->addWidget(new QLabel("Accueil")); // Definition of the "Layout" of the "Widget" setLayout(layoutPage); }
Home.h
#ifndef HOME_H #define HOME_H #include<QtWidgets> class Home : public QWidget { public: Home(); private: }; #endif // HOME_H
InterfaceA.cpp
#include"InterfaceA.h" InterfaceA::InterfaceA() { // Initialization QGridLayout *layoutPage; layoutPage = new QGridLayout(); layoutPage->setAlignment(Qt::AlignCenter); layoutPage->addWidget(new QLabel("Interface A")); // Definition of the "Layout" of the "Widget" setLayout(layoutPage); }
InterfaceA.h
#ifndef INTERFACEA_H #define INTERFACEA_H #include<QtWidgets> class InterfaceA : public QWidget { public: InterfaceA(); private: }; #endif // INTERFACEA_H
The complete example is visible on gitHub at this adress :
https://github.com/JuanDeDironne/qt_example_stacked_widgetswrote on 15 Feb 2023, 09:22 last edited by@Juan-de-Dironne
Looks like reasonableQStackedWidget
usage to me.And if so, how could I modify a member present in my main window from an interface...? (example with "stringTest")
Don't know what this means.
void MyMainWindow::showInterfaceA(){ m_stackedWidget->setCurrentIndex(m_stackedWidget->indexOf(widgetInterfaceA)); }
You can simplify this, since
QStackedWidget
offersm_stackedWidget->setCurrentWidget(widgetInterfaceA);
connect(m_actionQuit,SIGNAL(triggered(bool)),qApp,SLOT(quit()));
Old style
connect()
s withSIGNAL
/SLOT
macros were deprecated a decade ago. Please change over to:connect(m_actionQuit, &QAction::triggered, qApp, &QApplication::quit);
-
@Juan-de-Dironne
Looks like reasonableQStackedWidget
usage to me.And if so, how could I modify a member present in my main window from an interface...? (example with "stringTest")
Don't know what this means.
void MyMainWindow::showInterfaceA(){ m_stackedWidget->setCurrentIndex(m_stackedWidget->indexOf(widgetInterfaceA)); }
You can simplify this, since
QStackedWidget
offersm_stackedWidget->setCurrentWidget(widgetInterfaceA);
connect(m_actionQuit,SIGNAL(triggered(bool)),qApp,SLOT(quit()));
Old style
connect()
s withSIGNAL
/SLOT
macros were deprecated a decade ago. Please change over to:connect(m_actionQuit, &QAction::triggered, qApp, &QApplication::quit);
wrote on 15 Feb 2023, 09:49 last edited by@JonB
Thanks a lot for your answers.
For the old style of connection, I confess that I find out.And when I say "And if so, how could I modify a member present in my main window from an interface...? (example with "stringTest")".
This means that my "Interface A", for example, could retrieve input data that I would like to store in a variable of my "MainWindow" Class.
So that this variable is, for example, used on other Interfaces. -
@JonB
Thanks a lot for your answers.
For the old style of connection, I confess that I find out.And when I say "And if so, how could I modify a member present in my main window from an interface...? (example with "stringTest")".
This means that my "Interface A", for example, could retrieve input data that I would like to store in a variable of my "MainWindow" Class.
So that this variable is, for example, used on other Interfaces.wrote on 15 Feb 2023, 09:53 last edited by JonB@Juan-de-Dironne said in Using Stacked Widgets:
This means that my "Interface A", for example, could retrieve input data that I would like to store in a variable of my "MainWindow" Class.
If the "interface" classes are modal dialogs you could return whatever was entered after
QDialog::exec()
to be stored inMainWindow
. If they are modeless widgets (as you show) then I would probably write a signal which they emit with a parameter of the data, and have a slot inMainWindow
forward the data to other interface widgets if required. Or possibly save it in some "shared" application/UI object (e.g. perhaps a model) which all interfaces can see. What I would not do is have something which allows the interface widgets to make direct calls into theMainWindow
class. -
@Juan-de-Dironne said in Using Stacked Widgets:
This means that my "Interface A", for example, could retrieve input data that I would like to store in a variable of my "MainWindow" Class.
If the "interface" classes are modal dialogs you could return whatever was entered after
QDialog::exec()
to be stored inMainWindow
. If they are modeless widgets (as you show) then I would probably write a signal which they emit with a parameter of the data, and have a slot inMainWindow
forward the data to other interface widgets if required. Or possibly save it in some "shared" application/UI object (e.g. perhaps a model) which all interfaces can see. What I would not do is have something which allows the interface widgets to make direct calls into theMainWindow
class.wrote on 15 Feb 2023, 13:50 last edited by@JonB Thanks again for your reply.
You had already mentioned the "signals/slots" solution to communicate between the different classes in my Previous Post.
So I have to look into this solution.
But you mention the possibility of a shared object...? I don't see how to set this up...?
It would be a class...? Inherited from QOject...? But if so, how do you share it...?
I admit I don't know how to implement this solution. -
@JonB Thanks again for your reply.
You had already mentioned the "signals/slots" solution to communicate between the different classes in my Previous Post.
So I have to look into this solution.
But you mention the possibility of a shared object...? I don't see how to set this up...?
It would be a class...? Inherited from QOject...? But if so, how do you share it...?
I admit I don't know how to implement this solution.@Juan-de-Dironne said in Using Stacked Widgets:
It would be a class...? Inherited from QOject...? But if so, how do you share it...?
What ever you want to share. It can be a variable of some basic type or an instance of a struct/class. To share it you simply pass a pointer or reference to this object to all objects which needs to use it:
struct MyData { ... }; MyData data; MyClass myClass(&data); MyClass myClass2(&data);
-
@Juan-de-Dironne said in Using Stacked Widgets:
It would be a class...? Inherited from QOject...? But if so, how do you share it...?
What ever you want to share. It can be a variable of some basic type or an instance of a struct/class. To share it you simply pass a pointer or reference to this object to all objects which needs to use it:
struct MyData { ... }; MyData data; MyClass myClass(&data); MyClass myClass2(&data);
wrote on 15 Feb 2023, 15:17 last edited by@jsulm Thanks for your time and reply
So in my case I can create a structure like this :
MySharedStructure.hstruct MySharedStructure { QString myString = "123"; };
That I instantiate in "MyMainWindow.cpp" and pass a pointer to the constructor of my "InterfaceA" like this :
MyMainWindow.cpp
#include"MyMainWindow.h" #include"MySharedStructure.h" MyMainWindow::MyMainWindow() { setWindowTitle("Stacked Widgets"); setMinimumHeight(600); setMinimumWidth(600); MySharedStructure myData; ... ... // Definitions of the Different Widgets widgetHome = new Home; widgetHome->setObjectName("home"); widgetInterfaceA = new InterfaceA(&myData); widgetInterfaceA->setObjectName("interfaceA"); ... ...
InterfaceA.h
#include<QtWidgets> #include"MySharedStructure.h" class InterfaceA : public QWidget { Q_OBJECT public: InterfaceA(MySharedStructure*); }
With all this code in my constructor of my InterfaceA I can display if I want my character string stored in my structure like this :
InterfaceA.cpp#include"InterfaceA.h" InterfaceA::InterfaceA(MySharedStructure* dataFonc) { qDebug() << dataFonc->myString; }
In principle, this is how I should set things up to have a shared structure (in this case)...?
-
@jsulm Thanks for your time and reply
So in my case I can create a structure like this :
MySharedStructure.hstruct MySharedStructure { QString myString = "123"; };
That I instantiate in "MyMainWindow.cpp" and pass a pointer to the constructor of my "InterfaceA" like this :
MyMainWindow.cpp
#include"MyMainWindow.h" #include"MySharedStructure.h" MyMainWindow::MyMainWindow() { setWindowTitle("Stacked Widgets"); setMinimumHeight(600); setMinimumWidth(600); MySharedStructure myData; ... ... // Definitions of the Different Widgets widgetHome = new Home; widgetHome->setObjectName("home"); widgetInterfaceA = new InterfaceA(&myData); widgetInterfaceA->setObjectName("interfaceA"); ... ...
InterfaceA.h
#include<QtWidgets> #include"MySharedStructure.h" class InterfaceA : public QWidget { Q_OBJECT public: InterfaceA(MySharedStructure*); }
With all this code in my constructor of my InterfaceA I can display if I want my character string stored in my structure like this :
InterfaceA.cpp#include"InterfaceA.h" InterfaceA::InterfaceA(MySharedStructure* dataFonc) { qDebug() << dataFonc->myString; }
In principle, this is how I should set things up to have a shared structure (in this case)...?
wrote on 15 Feb 2023, 18:06 last edited by mpergand@Juan-de-Dironne
Hi,
One of the OOP principles is to only give each object the food they need :)So you can give your data a more structured form, like that:
struct Interface1Data { int i=1; }; struct Interface2Data { int i=2; }; struct AllData { int i=0; // global Interface1Data data1; Interface2Data data2; }; class Interface1 { public: Interface1(Interface1Data* d) : data(d) { qDebug()<<Q_FUNC_INFO<<data->i; } private: Interface1Data* data; }; class Interface2 { public: Interface2(Interface2Data* d) : data(d) { qDebug()<<Q_FUNC_INFO<<data->i; } private: Interface2Data* data; }; int main(int argc, char *argv[]) { AllData data; qDebug()<<data.i<<data.data1.i<<data.data2.i; Interface1 i1(&data.data1); Interface2 i2(&data.data2); return 0;
This way each interface deals with its own data and can't corrupt other interface ones.
-
@Juan-de-Dironne
Hi,
One of the OOP principles is to only give each object the food they need :)So you can give your data a more structured form, like that:
struct Interface1Data { int i=1; }; struct Interface2Data { int i=2; }; struct AllData { int i=0; // global Interface1Data data1; Interface2Data data2; }; class Interface1 { public: Interface1(Interface1Data* d) : data(d) { qDebug()<<Q_FUNC_INFO<<data->i; } private: Interface1Data* data; }; class Interface2 { public: Interface2(Interface2Data* d) : data(d) { qDebug()<<Q_FUNC_INFO<<data->i; } private: Interface2Data* data; }; int main(int argc, char *argv[]) { AllData data; qDebug()<<data.i<<data.data1.i<<data.data2.i; Interface1 i1(&data.data1); Interface2 i2(&data.data2); return 0;
This way each interface deals with its own data and can't corrupt other interface ones.
wrote on 16 Feb 2023, 11:05 last edited by@mpergand
Whaouh
At first my brain made knots when I read your code.
Once your code understood (which works perfectly) I adapted it to separate the classes in file.
And it gives that.
main.cpp
I made screenshots because I think it's easier to show the structure of the project that I put in place.
And before going further, is this project structure correct by applying your principle...? -
@mpergand
Whaouh
At first my brain made knots when I read your code.
Once your code understood (which works perfectly) I adapted it to separate the classes in file.
And it gives that.
main.cpp
AllData.h
Interface1
I made screenshots because I think it's easier to show the structure of the project that I put in place.
And before going further, is this project structure correct by applying your principle...?wrote on 16 Feb 2023, 13:45 last edited by@Juan-de-Dironne
Seems OK.I presume you want to save/load the all data structure, it's time to think about it ;)
-
@Juan-de-Dironne
Seems OK.I presume you want to save/load the all data structure, it's time to think about it ;)
wrote on 16 Feb 2023, 15:55 last edited by@mpergand
Thank you again for your answers and the time spent :)
And "to save/load the all data structure". That's to say...?Because I actually have a question. I have shared data but basically my "Interfaces" files should allow me to separate each Graphical Interface (each Stacked Widget).
And let's imagine that my "Interface 1" is a page with input of information and validation of it.
How could I save this information in my "AllData" structure so that it can be shared later...?
Hope to be clear in my explanations. -
@mpergand
Thank you again for your answers and the time spent :)
And "to save/load the all data structure". That's to say...?Because I actually have a question. I have shared data but basically my "Interfaces" files should allow me to separate each Graphical Interface (each Stacked Widget).
And let's imagine that my "Interface 1" is a page with input of information and validation of it.
How could I save this information in my "AllData" structure so that it can be shared later...?
Hope to be clear in my explanations.wrote on 16 Feb 2023, 16:24 last edited by mpergand@Juan-de-Dironne said in Using Stacked Widgets:
How could I save this information in my "AllData" structure so that it can be shared later...?
Currently each interface receives a pointer to the data, not a copy, that means:
Interface1Data* data
points to allData.data1
(same addresses)so in interface1
data->i=xx
is the same as
allData.data1.i=xx -
@Juan-de-Dironne said in Using Stacked Widgets:
How could I save this information in my "AllData" structure so that it can be shared later...?
Currently each interface receives a pointer to the data, not a copy, that means:
Interface1Data* data
points to allData.data1
(same addresses)so in interface1
data->i=xx
is the same as
allData.data1.i=xxwrote on 17 Feb 2023, 13:01 last edited by@mpergand
I'm trying to understand what you're explaining.
And if I understood correctly, you are telling me that I can access all the data present in my "Interface" classes from my "allData" class.
But in principle, I would like from my interface to be able to update "global" data.
And with this principle I do not see how to do it in fact. -
@mpergand
I'm trying to understand what you're explaining.
And if I understood correctly, you are telling me that I can access all the data present in my "Interface" classes from my "allData" class.
But in principle, I would like from my interface to be able to update "global" data.
And with this principle I do not see how to do it in fact.@Juan-de-Dironne said in Using Stacked Widgets:
I would like from my interface to be able to update "global" data
"global data" is bad design.
But if you pass pointer to your "global data" like @mpergand wrote you can modify this global data because you're not passing copies of the global data, but pointer to it. So, don't know what the problem is... -
@Juan-de-Dironne said in Using Stacked Widgets:
I would like from my interface to be able to update "global" data
"global data" is bad design.
But if you pass pointer to your "global data" like @mpergand wrote you can modify this global data because you're not passing copies of the global data, but pointer to it. So, don't know what the problem is...wrote on 20 Feb 2023, 09:16 last edited by@jsulm
In fact the principle is not to set up "global" data which could be accessible and shared between several interfaces...? Because...?
This concept is not good...?Because that's what I had actually envisioned.
An interface (interface 1) allowed me for example to display a connection screen and manage the identification.
Once logged in the "User ID" was stored in a "global structure".
This ID could be used by another interface (interface 2, interface 3, ...)But with pointer passing, we can access data from different interfaces. But no shared data in fact..? But no global data...?
-
@jsulm
In fact the principle is not to set up "global" data which could be accessible and shared between several interfaces...? Because...?
This concept is not good...?Because that's what I had actually envisioned.
An interface (interface 1) allowed me for example to display a connection screen and manage the identification.
Once logged in the "User ID" was stored in a "global structure".
This ID could be used by another interface (interface 2, interface 3, ...)But with pointer passing, we can access data from different interfaces. But no shared data in fact..? But no global data...?
@Juan-de-Dironne said in Using Stacked Widgets:
But no shared data in fact..?
What do you mean? If you pass pointer to some variable to different parts of your code then you're sharing this variable.
"Once logged in the "User ID" was stored in a "global structure"." - can you explain what exactly you mean if you write "global data"?
There should not be global data in a properly designed application. There should be clear ownership for each piece of data. For example your user id should be stored in some class which then provides it to whoever needs it.
-
@Juan-de-Dironne said in Using Stacked Widgets:
But no shared data in fact..?
What do you mean? If you pass pointer to some variable to different parts of your code then you're sharing this variable.
"Once logged in the "User ID" was stored in a "global structure"." - can you explain what exactly you mean if you write "global data"?
There should not be global data in a properly designed application. There should be clear ownership for each piece of data. For example your user id should be stored in some class which then provides it to whoever needs it.
wrote on 22 Feb 2023, 09:37 last edited byThank you all for your past and your answers. Indeed I learned through your answers to set up a sharing of data and especially to understand how to organize the data and divide them well into classes. Thank you again :) After... It's not won, I have to get used to this gymnastics of the mind but I have grasped the principle.
1/17