I am very much new to Qt and I have a simple doubt on switching between the windows.
I have a main window and I am creating a secondary window using a different class. I am hiding the primary window using hide( ) function and only the second window belonging to different class is visible. When the user presses the close button I have to show back the first window. My code looks something like this.
main.cpp
#include "FirstWindow.h"
int main(int argc, char *argv[])
{
FirstWindow w;
w.setAttribute( Qt :: WA_QuitOnClose );
w.show();
return a.exec();
}
#include "FirstWindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
FirstWindow w;
w.setAttribute( Qt :: WA_QuitOnClose );
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Important lines belonging to FirstWindow.h.
#include "SecondWindow.h"
{
Q_OBJECT
private:
SecondWindow * window2;
public:
void some_function( ){
this -> hide( );
window2 = new SecondWindow( );
window2 -> displayTheWindow( );
}
}
#include "SecondWindow.h"
class FirstWindow : public QDialog
{
Q_OBJECT
private:
SecondWindow * window2;
public:
void some_function( ){
this -> hide( );
window2 = new SecondWindow( );
window2 -> displayTheWindow( );
}
}
To copy to clipboard, switch view to plain text mode
Important lines belonging to SecondWindow.h
class SecondWindow
: public QDialog{
Q_OBJECT
private:
public slot:
void startFirstWindow( );
public:
SecondWindow( ){
connect( this, SIGNAL( rejected( ) ), this, SLOT( startFirstWindow( ) ) );
}
}
class SecondWindow : public QDialog
{
Q_OBJECT
private:
QDialog * dialog;
public slot:
void startFirstWindow( );
public:
SecondWindow( ){
dialog = new QDialog( );
connect( this, SIGNAL( rejected( ) ), this, SLOT( startFirstWindow( ) ) );
}
}
To copy to clipboard, switch view to plain text mode
Can anybody please help me how should I write the slot of startFirstWindow( ). I just want to make the first window visible again. Or is there another approach to this without much changes.
Thanks in advance for the help.
Bookmarks