PDA

View Full Version : Problem with connect?



Jake123
22nd January 2013, 15:18
Hey,

I am currently creating a program and have encountered a small problem.

I have a QWidget (MainMenu) with a pushbutton on and a slot called void MainMenu::button1Clicked();
On the click of this button, it closes MainMenu and opens up my second widget (PageTwo).

This works fine, however on PageTwo, the pushbutton to return to MainMenu does not work, it simply closes the widget as it is supposed to, but doesnt run MainMenu



Mainmenu class: (button works fine!)



MainMenu::MainMenu(QWidget *parent)
: QWidget(parent)

{

QWidget *MainMenu1 = new QWidget;

QPushButton *button1 = new QPushButton;
connect(button1, SIGNAL(clicked()),MainMenu1, SLOT(close()));
connect(button1,SIGNAL(clicked()),this,SLOT(button 1Clicked()));

MainMenu -> show();

}



void MainMenu::button1Clicked()
{
Page2 w;

}


My second class , it opens up fine but will not run MainMenu when the button is clicked as it does the first time



Page2::Page2(QWidget *parent)
: QWidget(parent)
{


QWidget *PageTwo = new QWidget;

QPushButton *button2 = new QPushButton;
connect(button2, SIGNAL(clicked()),PageTwo, SLOT(close()));
connect(button2,SIGNAL(clicked()),this,SLOT(button 2Clicked()));

PageTwo -> show();

}



void Page2::button2Clicked()
{
MainMenu w;

}





Thanks in advance for any replies.. It is really confusing me as to why the first button works perfectly fine but the second one will not even though the code is practically the same...
P.S i am not recieving any errors, main menu is just not showing!

wysota
22nd January 2013, 15:59
Please show real code. What you posted will not even compile.

Santosh Reddy
22nd January 2013, 16:08
Problem in you code:
1. You creating objects of the same class in the class constructor, this will never work. The reson you feel it works if some kind of errror. Did you ever notice that you have two MainMenu's :eek:
2. Create Objects using new operator (i.e. on the heap).

Jake123
22nd January 2013, 16:20
Thanks, but that doesn't answer my question, that is just spotting errors in the code which i made to try and highlight and give an example of the problem. The fact is, why will my program run and even allow the first set of pushbuttons to work, linking to the next widget - but after that no more pushbuttons will work. They simply execute the first command (to close to widget) and do not run the destination class

Lykurg
22nd January 2013, 16:33
Thanks, but that doesn't answer my questionYes, but without seeing a minimal compilable example demonstrating your problem we hardly could.

Santosh Reddy
22nd January 2013, 16:39
See if you can userstand this code (Note this works perfectly)


MainMenu::MainMenu(QWidget *parent)
: QWidget(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
QPushButton *button1 = new QPushButton("PushButton 1", this);
connect(button1,SIGNAL(clicked()),this,SLOT(button 1Clicked()));

this->show();
}

void MainMenu::button1Clicked()
{
Page2 *w = new Page2();
w->show();

this->close();
}

Page2::Page2(QWidget *parent)
: QWidget(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
QPushButton *button2 = new QPushButton("PushButton 2", this);
connect(button2,SIGNAL(clicked()),this,SLOT(button 2Clicked()));

this->show();
}

void Page2::button2Clicked()
{
MainMenu *w = new MainMenu();
w->show();

this->close();
}


Note: It will work functionally only

wysota
22nd January 2013, 16:39
Thanks, but that doesn't answer my question, that is just spotting errors in the code which i made to try and highlight and give an example of the problem. The fact is, why will my program run and even allow the first set of pushbuttons to work, linking to the next widget - but after that no more pushbuttons will work. They simply execute the first command (to close to widget) and do not run the destination class

If the code is made up and not a real world case, why should anyone bother fixing it?

You are aware what the following code does, right? I mean, you know "obj" will be destroyed when fun() returns?


void fun() {
Class obj;
}

I think what OP wants (but is unable to express his wishes) is to open back the original MainMenu instance.

Jake123
22nd January 2013, 17:04
(Real Code)

So When i click my quad button, it successfuly runs the Quad class and opens the quad widget, aswell as closing the main menu widget (as it should)
However when I click the Main Menu button on the quad page, it closes the widget (as it should) but DOES NOT run the main menu widget.


Main Menu Class:


#include "mainmenu.h"
#include "quadratic.h"



MainMenu::MainMenu(QWidget *parent)
: QWidget(parent)

{

QWidget *MainMenuW = new QWidget;

MainMenuW -> setWindowTitle("Mainmenu");
MainMenuW -> setStyleSheet("background-image: url(Graphics/MainMenu.png)");
QSize appsize(1200,650);
MainMenuW -> setFixedSize(appsize);
MainMenuW -> resize(appsize);

QSize ButtonSize(200,68);
QPushButton *Menu2Menu = new QPushButton;
Menu2Menu -> setFixedSize(ButtonSize);
Menu2Menu -> setStyleSheet("background-image: url(Buttons/MM1.png)");



QPushButton *Menu2Quad = new QPushButton;
Menu2Quad -> setFixedSize(ButtonSize);
Menu2Quad -> setStyleSheet("background-image: url(Buttons/Q.png)");
connect(Menu2Quad, SIGNAL(clicked()),MainMenuW, SLOT(close()));
connect(Menu2Quad,SIGNAL(clicked()),this,SLOT(Menu 2QuadClicked()));


QPushButton *Menu2Trig = new QPushButton;
Menu2Trig -> setFixedSize(ButtonSize);
Menu2Trig -> setStyleSheet("background-image: url(Buttons/T.png)");




QPushButton *Menu2Pythag = new QPushButton;
Menu2Pythag -> setFixedSize(ButtonSize);
Menu2Pythag -> setStyleSheet("background-image: url(Buttons/P.png)");




QPushButton *Menu2Simul = new QPushButton;
Menu2Simul -> setFixedSize(ButtonSize);
Menu2Simul -> setStyleSheet("background-image: url(Buttons/S.png)");




QPushButton *Menu22D = new QPushButton;
Menu22D -> setFixedSize(ButtonSize);
Menu22D -> setStyleSheet("background-image: url(Buttons/2.png)");




QPushButton *Menu23D = new QPushButton;
Menu23D -> setFixedSize(ButtonSize);
Menu23D -> setStyleSheet("background-image: url(Buttons/3.png)");


QSpacerItem *Spacer0001 = new QSpacerItem(100, 450, QSizePolicy::Ignored, QSizePolicy::Ignored);




QGridLayout *MainMenuLayout = new QGridLayout;
MainMenuLayout -> addItem(Spacer0001,1,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Menu,3,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Quad,4,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Pythag,5,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Trig,6,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Simul,7,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu22D,8,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu23D,9,1,1,1,Qt::AlignLeft);
MainMenuW-> setLayout(MainMenuLayout);




MainMenuW -> show();

}

void MainMenu::Menu2QuadClicked()
{
Quadratic w;


}



Quad Class


#include "mainmenu.h"
#include "quadratic.h"


Quadratic::Quadratic(QWidget *parent) :
QWidget(parent)
{

QWidget *Quad = new QWidget;

Quad -> setWindowTitle("Quad");
Quad -> setStyleSheet("background-image: url(Graphics/Quadratics.png)");
QSize appsize(1200,650);
Quad -> setFixedSize(appsize);
Quad -> resize(appsize);

QSize ButtonSize(200,68);
QPushButton *Quad2Menu = new QPushButton;
Quad2Menu -> setFixedSize(ButtonSize);
Quad2Menu -> setStyleSheet("background-image: url(Buttons/MM.png)");
connect(Quad2Menu,SIGNAL(clicked()),Quad,SLOT(clos e()));
connect(Quad2Menu,SIGNAL(clicked()),this,SLOT(Quad 2MenuClicked()));


QPushButton *Quad2Quad = new QPushButton;
Quad2Quad -> setFixedSize(ButtonSize);
Quad2Quad -> setStyleSheet("background-image: url(Buttons/Q1.png)");



QPushButton *Quad2Trig = new QPushButton;
Quad2Trig -> setFixedSize(ButtonSize);
Quad2Trig -> setStyleSheet("background-image: url(Buttons/T.png)");




QPushButton *Quad2Pyth = new QPushButton;
Quad2Pyth -> setFixedSize(ButtonSize);
Quad2Pyth -> setStyleSheet("background-image: url(Buttons/P.png)");




QPushButton *Quad2Sim = new QPushButton;
Quad2Sim -> setFixedSize(ButtonSize);
Quad2Sim -> setStyleSheet("background-image: url(Buttons/S.png)");



QPushButton *Quad22D = new QPushButton;
Quad22D -> setFixedSize(ButtonSize);
Quad22D -> setStyleSheet("background-image: url(Buttons/2.png)");




QPushButton *Quad23D = new QPushButton;
Quad23D -> setFixedSize(ButtonSize);
Quad23D -> setStyleSheet("background-image: url(Buttons/3.png)");


QSpacerItem *Spacer0001 = new QSpacerItem(100, 450, QSizePolicy::Ignored, QSizePolicy::Ignored);




QGridLayout *QuadLayout = new QGridLayout;
QuadLayout -> addItem(Spacer0001,1,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Menu,3,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Quad,4,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Pyth,5,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Trig,6,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Sim,7,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad22D,8,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad23D,9,1,1,1,Qt::AlignLeft);
Quad -> setLayout(QuadLayout);



Quad -> show();



}

void Quadratic::Quad2MenuClicked()
{
MainMenu w;
}



The compiler does not give me any errors, so im confused to why the first button would work but the second one doesnt.
Also, I have tried running the QUAD widget first instead of the MainMenu. The result was that again the first button worked, but then the second didnt (basically the same just in reverse)

Any help is much appreciated!

P.s Incase it is not clear, my wish is to firstly open up MainMenu (Works) then click a button to open Quad (works) but then from Quad, return to Main Menu using another button (doesnt work)

Jake123
22nd January 2013, 17:08
Yeah, i understand that and you are correct in understanding what i want.. I have posted my full code in a new thread :)

wysota
22nd January 2013, 17:14
Yeah, i understand that
So why do you do that?

Jake123
22nd January 2013, 17:38
So why do you do that?


In the first class (MainMenu) it worked in running the Quad class and therefore creating the widget - so i assumed it was the correct way to do it. What would you suggest instead?

wysota
22nd January 2013, 18:17
I would suggest to read a bit about object oriented programming and C++ in particular before taking on any serious programming. Using Qt without decent C++ skills is going to backfire sooner or later.

Santosh Reddy
22nd January 2013, 20:13
This is defenetly not what you should do, but just in case if you want to see your code work the way you expect for now, have a look below



class MainMenu : public QWidget
{
Q_OBJECT
public:
explicit MainMenu(QWidget *parent = 0);
public slots:
void Menu2QuadClicked();
};

class Quadratic : public QWidget
{
Q_OBJECT
public:
explicit Quadratic(QWidget *parent = 0);
public slots:
void Quad2MenuClicked();
};

MainMenu::MainMenu(QWidget *parent)
: QWidget(parent)
{
QWidget *MainMenuW = this;

MainMenuW -> setWindowTitle("Mainmenu");
MainMenuW -> setStyleSheet("background-image: url(Graphics/MainMenu.png)");
QSize appsize(1200,650);
MainMenuW -> setFixedSize(appsize);
MainMenuW -> resize(appsize);

QSize ButtonSize(200,68);
QPushButton *Menu2Menu = new QPushButton;
Menu2Menu -> setFixedSize(ButtonSize);
Menu2Menu -> setStyleSheet("background-image: url(Buttons/MM1.png)");

QPushButton *Menu2Quad = new QPushButton;
Menu2Quad -> setFixedSize(ButtonSize);
Menu2Quad -> setStyleSheet("background-image: url(Buttons/Q.png)");
connect(Menu2Quad, SIGNAL(clicked()),MainMenuW, SLOT(close()));
connect(Menu2Quad,SIGNAL(clicked()),this,SLOT(Menu 2QuadClicked()));

QPushButton *Menu2Trig = new QPushButton;
Menu2Trig -> setFixedSize(ButtonSize);
Menu2Trig -> setStyleSheet("background-image: url(Buttons/T.png)");

QPushButton *Menu2Pythag = new QPushButton;
Menu2Pythag -> setFixedSize(ButtonSize);
Menu2Pythag -> setStyleSheet("background-image: url(Buttons/P.png)");

QPushButton *Menu2Simul = new QPushButton;
Menu2Simul -> setFixedSize(ButtonSize);
Menu2Simul -> setStyleSheet("background-image: url(Buttons/S.png)");

QPushButton *Menu22D = new QPushButton;
Menu22D -> setFixedSize(ButtonSize);
Menu22D -> setStyleSheet("background-image: url(Buttons/2.png)");

QPushButton *Menu23D = new QPushButton;
Menu23D -> setFixedSize(ButtonSize);
Menu23D -> setStyleSheet("background-image: url(Buttons/3.png)");

QSpacerItem *Spacer0001 = new QSpacerItem(100, 450, QSizePolicy::Ignored, QSizePolicy::Ignored);

QGridLayout *MainMenuLayout = new QGridLayout;
MainMenuLayout -> addItem(Spacer0001,1,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Menu,3,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Quad,4,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Pythag,5,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Trig,6,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Simul,7,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu22D,8,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu23D,9,1,1,1,Qt::AlignLeft);
MainMenuW-> setLayout(MainMenuLayout);

MainMenuW -> show();
}

void MainMenu::Menu2QuadClicked()
{
Quadratic *w = new Quadratic;
w->show();
}

Quadratic::Quadratic(QWidget *parent)
: QWidget(parent)
{
QWidget *Quad = this;

Quad -> setWindowTitle("Quad");
Quad -> setStyleSheet("background-image: url(Graphics/Quadratics.png)");
QSize appsize(1200,650);
Quad -> setFixedSize(appsize);
Quad -> resize(appsize);

QSize ButtonSize(200,68);
QPushButton *Quad2Menu = new QPushButton;
Quad2Menu -> setFixedSize(ButtonSize);
Quad2Menu -> setStyleSheet("background-image: url(Buttons/MM.png)");
connect(Quad2Menu,SIGNAL(clicked()),Quad,SLOT(clos e()));
connect(Quad2Menu,SIGNAL(clicked()),this,SLOT(Quad 2MenuClicked()));

QPushButton *Quad2Quad = new QPushButton;
Quad2Quad -> setFixedSize(ButtonSize);
Quad2Quad -> setStyleSheet("background-image: url(Buttons/Q1.png)");

QPushButton *Quad2Trig = new QPushButton;
Quad2Trig -> setFixedSize(ButtonSize);
Quad2Trig -> setStyleSheet("background-image: url(Buttons/T.png)");

QPushButton *Quad2Pyth = new QPushButton;
Quad2Pyth -> setFixedSize(ButtonSize);
Quad2Pyth -> setStyleSheet("background-image: url(Buttons/P.png)");

QPushButton *Quad2Sim = new QPushButton;
Quad2Sim -> setFixedSize(ButtonSize);
Quad2Sim -> setStyleSheet("background-image: url(Buttons/S.png)");

QPushButton *Quad22D = new QPushButton;
Quad22D -> setFixedSize(ButtonSize);
Quad22D -> setStyleSheet("background-image: url(Buttons/2.png)");

QPushButton *Quad23D = new QPushButton;
Quad23D -> setFixedSize(ButtonSize);
Quad23D -> setStyleSheet("background-image: url(Buttons/3.png)");

QSpacerItem *Spacer0001 = new QSpacerItem(100, 450, QSizePolicy::Ignored, QSizePolicy::Ignored);

QGridLayout *QuadLayout = new QGridLayout;
QuadLayout -> addItem(Spacer0001,1,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Menu,3,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Quad,4,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Pyth,5,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Trig,6,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Sim,7,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad22D,8,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad23D,9,1,1,1,Qt::AlignLeft);
Quad -> setLayout(QuadLayout);

Quad -> show();
}


Here is how the story goes.

1. Create and show MainMenu (Say M1)
2. Click PushButton (Say MP1) of M1, this will create and show a new Quadratic (Say Q1) and close M1.
3. Click PushButton (Say QP1) of Q1, this will create and show a new MainMenu (Say M2) and close Q1. Important part is that M1 is closed in earlier step and no way get to it, an hence a memory leak.
4. Click PushButton on M2 will repeat the story from step 2.

Is this the story you wanted? :cool:

Jake123
23rd January 2013, 16:41
This is defenetly not what you should do, but just in case if you want to see your code work the way you expect for now, have a look below



class MainMenu : public QWidget
{
Q_OBJECT
public:
explicit MainMenu(QWidget *parent = 0);
public slots:
void Menu2QuadClicked();
};

class Quadratic : public QWidget
{
Q_OBJECT
public:
explicit Quadratic(QWidget *parent = 0);
public slots:
void Quad2MenuClicked();
};

MainMenu::MainMenu(QWidget *parent)
: QWidget(parent)
{
QWidget *MainMenuW = this;

MainMenuW -> setWindowTitle("Mainmenu");
MainMenuW -> setStyleSheet("background-image: url(Graphics/MainMenu.png)");
QSize appsize(1200,650);
MainMenuW -> setFixedSize(appsize);
MainMenuW -> resize(appsize);

QSize ButtonSize(200,68);
QPushButton *Menu2Menu = new QPushButton;
Menu2Menu -> setFixedSize(ButtonSize);
Menu2Menu -> setStyleSheet("background-image: url(Buttons/MM1.png)");

QPushButton *Menu2Quad = new QPushButton;
Menu2Quad -> setFixedSize(ButtonSize);
Menu2Quad -> setStyleSheet("background-image: url(Buttons/Q.png)");
connect(Menu2Quad, SIGNAL(clicked()),MainMenuW, SLOT(close()));
connect(Menu2Quad,SIGNAL(clicked()),this,SLOT(Menu 2QuadClicked()));

QPushButton *Menu2Trig = new QPushButton;
Menu2Trig -> setFixedSize(ButtonSize);
Menu2Trig -> setStyleSheet("background-image: url(Buttons/T.png)");

QPushButton *Menu2Pythag = new QPushButton;
Menu2Pythag -> setFixedSize(ButtonSize);
Menu2Pythag -> setStyleSheet("background-image: url(Buttons/P.png)");

QPushButton *Menu2Simul = new QPushButton;
Menu2Simul -> setFixedSize(ButtonSize);
Menu2Simul -> setStyleSheet("background-image: url(Buttons/S.png)");

QPushButton *Menu22D = new QPushButton;
Menu22D -> setFixedSize(ButtonSize);
Menu22D -> setStyleSheet("background-image: url(Buttons/2.png)");

QPushButton *Menu23D = new QPushButton;
Menu23D -> setFixedSize(ButtonSize);
Menu23D -> setStyleSheet("background-image: url(Buttons/3.png)");

QSpacerItem *Spacer0001 = new QSpacerItem(100, 450, QSizePolicy::Ignored, QSizePolicy::Ignored);

QGridLayout *MainMenuLayout = new QGridLayout;
MainMenuLayout -> addItem(Spacer0001,1,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Menu,3,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Quad,4,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Pythag,5,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Trig,6,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu2Simul,7,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu22D,8,1,1,1,Qt::AlignLeft);
MainMenuLayout -> addWidget(Menu23D,9,1,1,1,Qt::AlignLeft);
MainMenuW-> setLayout(MainMenuLayout);

MainMenuW -> show();
}

void MainMenu::Menu2QuadClicked()
{
Quadratic *w = new Quadratic;
w->show();
}

Quadratic::Quadratic(QWidget *parent)
: QWidget(parent)
{
QWidget *Quad = this;

Quad -> setWindowTitle("Quad");
Quad -> setStyleSheet("background-image: url(Graphics/Quadratics.png)");
QSize appsize(1200,650);
Quad -> setFixedSize(appsize);
Quad -> resize(appsize);

QSize ButtonSize(200,68);
QPushButton *Quad2Menu = new QPushButton;
Quad2Menu -> setFixedSize(ButtonSize);
Quad2Menu -> setStyleSheet("background-image: url(Buttons/MM.png)");
connect(Quad2Menu,SIGNAL(clicked()),Quad,SLOT(clos e()));
connect(Quad2Menu,SIGNAL(clicked()),this,SLOT(Quad 2MenuClicked()));

QPushButton *Quad2Quad = new QPushButton;
Quad2Quad -> setFixedSize(ButtonSize);
Quad2Quad -> setStyleSheet("background-image: url(Buttons/Q1.png)");

QPushButton *Quad2Trig = new QPushButton;
Quad2Trig -> setFixedSize(ButtonSize);
Quad2Trig -> setStyleSheet("background-image: url(Buttons/T.png)");

QPushButton *Quad2Pyth = new QPushButton;
Quad2Pyth -> setFixedSize(ButtonSize);
Quad2Pyth -> setStyleSheet("background-image: url(Buttons/P.png)");

QPushButton *Quad2Sim = new QPushButton;
Quad2Sim -> setFixedSize(ButtonSize);
Quad2Sim -> setStyleSheet("background-image: url(Buttons/S.png)");

QPushButton *Quad22D = new QPushButton;
Quad22D -> setFixedSize(ButtonSize);
Quad22D -> setStyleSheet("background-image: url(Buttons/2.png)");

QPushButton *Quad23D = new QPushButton;
Quad23D -> setFixedSize(ButtonSize);
Quad23D -> setStyleSheet("background-image: url(Buttons/3.png)");

QSpacerItem *Spacer0001 = new QSpacerItem(100, 450, QSizePolicy::Ignored, QSizePolicy::Ignored);

QGridLayout *QuadLayout = new QGridLayout;
QuadLayout -> addItem(Spacer0001,1,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Menu,3,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Quad,4,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Pyth,5,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Trig,6,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad2Sim,7,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad22D,8,1,1,1,Qt::AlignLeft);
QuadLayout -> addWidget(Quad23D,9,1,1,1,Qt::AlignLeft);
Quad -> setLayout(QuadLayout);

Quad -> show();
}


Here is how the story goes.

1. Create and show MainMenu (Say M1)
2. Click PushButton (Say MP1) of M1, this will create and show a new Quadratic (Say Q1) and close M1.
3. Click PushButton (Say QP1) of Q1, this will create and show a new MainMenu (Say M2) and close Q1. Important part is that M1 is closed in earlier step and no way get to it, an hence a memory leak.
4. Click PushButton on M2 will repeat the story from step 2.

Is this the story you wanted? :cool:



That is perfect, thanks! The buttons work just how I want them to - However , now my background stylesheet is not displaying, any ideas on how to fix this? Also, you mentioned that this is defenetly not the way to do things - so what would you suggest in order for me to achieve best results?

Thank you for being patient. I have made a few programs before in console with codeblocks in C++ but Qt is a completely new experience for me.

Added after 22 minutes:

I solved the stylesheet problem by instead using



QPalette palette;
palette.setBrush(QPalette::Window, QBrush(QPixmap("Graphics/MainMenu.png")));
this->setPalette(palette);