I am trying to pass data from a Qdialog
(Login dialog) to my mainWindow
after a successful login and was wondering if it is possible to use Signals and slots to achieve this. Here is my Main.cpp file so far in which I connect my Login Dialog to main window:
int main(int argc, char *argv[]){
QApplication a(argc, argv);
Login l;
l.createConnection();
MainWindow w;
l.show();
QObject::connect(&l, SIGNAL(accept()), &w, SLOT(show()));
QObject::connect(&w, SIGNAL(Logout()), &l, SLOT(show()));
return a.exec();
}
The signal accept emits from the Dialog after the user inserts correct username/password and I would like afterwards to pass the information relative to this user to my main window.
The user class I'm trying to pass:
class User
{
QString ID;
QString username;
QString password;
QString name;
QString Status;
public:
User();
User(QString, QString, QString, QString, QString);
~User();
};
What is the best approach for this?
accept
signal with the data. Something likesignals: void accept(Data data){...}
in theLogin
class andQObject::connect(&l, &Loging::accept, [&](Data data){w.setData(data); w.show();});
when connecting the login window and the main window. – Donald DuckQ_DECLARE_METATYPE (Data);
– eyllanesc