user3131037
user3131037

Reputation: 473

Back button in qt

I'm trying to implement a simple Lotka-Voltery simulation. I have a main QDialog Class in which I put three buttons to choose the options.

  1. Button for simple simulation,

  2. simulation with hideouts,

  3. simulation with competition.

Each of these options are implemented in separated class.

When I click on each button I use connect function to close option window and show appropriate QDialog window (one of three options) and it works well.

I have problem with implementing back button. Analogously I can put an object of an option_window class, put in each windows and make a connection function like this:

connect ( back_button,SIGNAL(clicked()), Options_Window, SLOT(show()));  

but it is not going to work because in my option_window class I already have objects of the rest of class.

It looks like the class A have an object of class B inside, and the class B have an object of class A inside. It won't work. What should I do ?

Here is a Window_Option header file.

namespace Ui {
    class Window_Option;
}

class Window_Option : public QDialog
{
    Q_OBJECT

public:
    explicit Window_Option(QWidget *parent = 0);
    ~Window_Option();
    MainWindow *simple;
    MainWindowHide *hideout;
    MainWindowComp *competition;

private:
    Ui::Window_Option *ui;
};       

Upvotes: 1

Views: 3213

Answers (1)

lrineau
lrineau

Reputation: 6274

It looks like the class A have an object of class B inside, and the class B have an object of class A inside. It won't work. What should I do ?

Said like that, that is impossible. But if, instead, the class B contains a pointer to an object of class A, you can forward-declare the class A before the definition of class B.

Upvotes: 1

Related Questions