Show mainwindow from another window
-
Hello
I want to show the main window from another window.
For instance
i have a login form and i managed to open another window from the login form usingthis->hide(); emp=new employeeinfo(); emp->show();
Now i have a pushbutton on the employeeinfo ui and i want to go back to the main login window when i press the push button.
i don't know what to include.
i tried to include "mainwindow.h" and then declare mainwindow *main; in private
However , it says 'MainWindow' does not name a type. -
hi
this->hide(); <<< this hide your existing mainwindow?so maybe do
this->hide();
emp=new employeeinfo(this);
emp->show();then in EMP
you can say Parent->Show() and it will be visible again. -
This is not really clear. The error suggests you need to add a forward declaration of 'MainWindow' in the header of your other window (?).
#ifndef HEADERFILE #define HEADERFILE class MainWindow; // forward declaration class MyOtherWindow : public QWidget { Q_OBJECT public: MyOtherWindow(QWidget *parent=0, Qt::WindowFlags flags=0); ~MyOtherWindow(void); private: MainWindow *main_window; // forward declaration required otherwise this is an error }; #endif
-
Hello thank you , this worked :)
However, i have a question regarding this.
Is this the right way to toggle between windows.
I mean we hide the window using this->hide(); , so the window is still using the memory , its just hidden. If i make a program with a lot of windows , all of them will just be hidden and not closed.
So is this the right way , or is there a different way to load another window from mainwindow.
Thank you :) -
Hi
well, normally a program have a mainwindow and pop dialogs over it.
So mainwin is always shown and the dialogs are created/shown/deletedThere is nothing wrong in hiding the window but it really depends on what you want.
You can create a new window each time, but then you are not going back to it, you
just show a new version.
in any place in the program , you couldMainWindow *newmain= new MainWindow()
newmain->show()and have a brand new mainwindow
but its not so common to do with mainwindow, its more for dialogs or
other type of windows.your design do sound like the normal one where u pop a dialog over mainwindow.
except you want to hide mainwindow.So its not complete crazy :)
-
@ronyNS
hi i think u can use Qt::WindowMaximizeButtonHint; and other
setWindowFlags flags to add such min/max.well im not really sure what you are after but
say u show mainwindow
then do
LoginDialog d1;
ProfileDialog d2;if ( d1.exec() == QDialog::Accepted ) {
d2.exec();
} else
Login in failed. what ever to happenit would first show login (blocking mainwin)
if user press ok, then show profile. still blocking mainwindetc.