0

So I'm really new to QT and there's this problem i'm facing which i can't understand at all. I've got a program that has a next button on each page and a back button on some. All the next buttons i've implemented are working perfectly fine, but the back button isn't, even though i implemented it the same way as i did the others, which i saw online.

This is the header file for the third page which has the back button:

//ThirdPage header file
#ifndef THIRDPAGE_H
#define THIRDPAGE_H

#include <QDialog>
#include "secondpage.h"

namespace Ui {
class ThirdPage;
}

class ThirdPage : public QDialog
{
    Q_OBJECT

public:
    explicit ThirdPage(QWidget *parent = 0);
    ~ThirdPage();

private slots:
    void on_backButton_clicked();

private:
    Ui::ThirdPage *ui;
    SecondPage *secPage;
};

#endif // THIRDPAGE_H

This is the cpp file for the third page:

//third page cpp file
#include "thirdpage.h"
#include "ui_thirdpage.h"
#include "secondpage.h"

ThirdPage::ThirdPage(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ThirdPage)
{
    ui->setupUi(this);
    //setFixedSize(854,480);
    setMinimumSize(854,480);
}

ThirdPage::~ThirdPage()
{
    delete ui;
}

void ThirdPage::on_backButton_clicked()
{
    hide();
    secPage = new SecondPage(this);
    secPage->show();

}

And these are the header and cpp files for the second page, that should open when the back button is pressed

//Second Page header file
#ifndef SECONDPAGE_H
#define SECONDPAGE_H

#include <QDialog>
#include "thirdpage.h"

namespace Ui {
class SecondPage;
}

class SecondPage : public QDialog
{
    Q_OBJECT

public:
    explicit SecondPage(QWidget *parent = 0);
    ~SecondPage();

private slots:
    void on_pushButton_clicked();

private:
    Ui::SecondPage *ui;
    ThirdPage *thirdPage;
};
#endif // SECONDPAGE_H

Second Page cpp:

//Second Page cpp file
#include "secondpage.h"
#include "ui_secondpage.h"
#include "thirdpage.h"

SecondPage::SecondPage(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SecondPage)
{
    ui->setupUi(this);
    //setFixedSize(854,480);
    setMinimumSize(854,480);
}

SecondPage::~SecondPage()
{
    delete ui;
}

void SecondPage::on_pushButton_clicked()
{
    QString nameOfClient = ui->NameOfClient->text();
    QString designation = ui->DesignationOfCompany->text();
    QString nameOfCompany = ui->NameOfIndustry->text();
    QString addressOfCompany = ui->Address->text();
    QString contactNumber = ui->ContactNumber->text();
    QString annualProductionCapacity = ui->AnnualProductionCapacity->text();

    QString clientDetails[6] = {nameOfClient,designation,nameOfCompany,addressOfCompany,contactNumber,};

    hide();
    thirdPage = new ThirdPage(this);
    thirdPage->show();
}

The error i'm getting is in thirdpage.h which is:

error: 'SecondPage' does not name a type
     SecondPage *secPage;
     ^

Anybody can see where the problem is?

Vishaal Shankar
  • 1,648
  • 14
  • 26
Asad Nawaz
  • 355
  • 1
  • 3
  • 14
  • 4
    You have a *circular dependency*, where `thirdpage.h` includes `secondpage.h` which includes `thirdpage.h` and so on and on. You need to break that circle, for example by stopping the inclusion and use *forward declarations* of the classes instead. – Some programmer dude Feb 10 '18 at 10:33
  • Stopping the **cross inclusion** would cause another compiler issue when compiler seeks the implementations! .. its unavoidable (in _concept_ for this code), _Forward declaration_ would eliminate the problem. Qt by default uses [Include guard](https://en.wikipedia.org/wiki/Include_guard). – Mohammad Kanan Feb 10 '18 at 13:31
  • [How are circular #includes resolved?](https://stackoverflow.com/questions/3127171/how-are-circular-includes-resolved) – Mohammad Kanan Feb 10 '18 at 13:44
  • @Someprogrammerdude thanks, a quick google search on forward declarations cleared my problem. :) – Asad Nawaz Feb 10 '18 at 14:53

0 Answers0