Access the function of another window.
-
Hello.
There is a program in it there is a MainWindow window and a Configuration settings window.
The ReadXML function is called inside the Configuration window. Everything works, but I will not mind how you can call this very function (ReadXML) when starting the MainWindow. I looked and read the literature and recommend using slots and signals.
What I tried to do:
In the mainwindow.h file, I added the signalssignal: void credentials();
In the configuration.h file, I added the
public slots slot: void ReadXML();
And at the very beginning of the program in the mainwindow.cpp file, I tried to connect
ui- > setupUi (this); connect(this, &MainWindow::credentials, &Configuration::Configuration, &Configuration::ReadXML);
Please tell me how to do it.
-
@kipalex said in Access the function of another window.:
signal:
public slots slot:
Please start by correcting these for yourself so it compiles. You did not find either of these out there on the web. Use the documentation or examples, there are so many you don't need to make someone else write it for you. Though see below as you may not need either.
connect(this, &MainWindow::credentials, &Configuration::Configuration, &Configuration::ReadXML);
&Configuration::Configuration
is incorrect. It requires a pointer to the slot object. If you are creating a "Configuration window" as you say then use the instance here.If the main window creates the configuration window then there is no point having a signal, connecting and emitting. It might as well just call
Configuration::ReadXML()
when it wants to.