error building a window application
-
Hi,
I'm stuck at debugging an issue.
I have two windows
StageOneMainandClinicalProtocolWindowI want to open
ClinicalProtocolWindowfromStageOneMainand go back.On
StageOneMainI did the following:#ifndef STAGEONEMAIN_H #define STAGEONEMAIN_H #include <QMainWindow> #include "clinicalprotocolwindow.h" QT_BEGIN_NAMESPACE namespace Ui { class StageOneMain; } QT_END_NAMESPACE class StageOneMain : public QMainWindow { Q_OBJECT public: StageOneMain(QString, QWidget *parent = nullptr); ~StageOneMain(); ClinicalProtocolWindow *clinwindow; QString pLabel; private: Ui::StageOneMain *ui; }; #endif // STAGEONEMAIN_H.cpp
void StageOneMain::on_pushButton_programs_clicked() { this->close(); clinwindow = new ClinicalProtocolWindow(pLabel, nullptr); clinwindow -> setAttribute(Qt::WA_DeleteOnClose); clinwindow -> show(); }and
ClinicalProtocolWindowas follows:#ifndef CLINICALPROTOCOLWINDOW_H #define CLINICALPROTOCOLWINDOW_H #include <QMainWindow> #include "stageonemain.h" namespace Ui { class ClinicalProtocolWindow; } class ClinicalProtocolWindow : public QMainWindow { Q_OBJECT public: explicit ClinicalProtocolWindow(QString, QWidget *parent = nullptr); ~ClinicalProtocolWindow(); QString pLabel; private slots: void on_pushButton_clicked(); private: Ui::ClinicalProtocolWindow *ui; }; #endif // CLINICALPROTOCOLWINDOW_Hand .cpp
#include "clinicalprotocolwindow.h" #include "ui_clinicalprotocolwindow.h" ClinicalProtocolWindow::ClinicalProtocolWindow(QString patientLabel, QWidget *parent) : QMainWindow(parent), ui(new Ui::ClinicalProtocolWindow) { ui->setupUi(this); pLabel = patientLabel; } ClinicalProtocolWindow::~ClinicalProtocolWindow() { delete ui; } void ClinicalProtocolWindow::on_pushButton_clicked() { }I get the errors pointing below
ClinicalProtocolWindow *clinwindow;and the errors are:
stageonemain.h:33: error: C2143: syntax error: missing ';' before '*' stageonemain.h:33: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int stageonemain.h:33: error: C2238: unexpected token(s) preceding ';'It seems that I have overlooked something. I'm feeling frustrated and stuck on this problem.
Can you spot any issues here?
Thanks
-
Hi,
I'm stuck at debugging an issue.
I have two windows
StageOneMainandClinicalProtocolWindowI want to open
ClinicalProtocolWindowfromStageOneMainand go back.On
StageOneMainI did the following:#ifndef STAGEONEMAIN_H #define STAGEONEMAIN_H #include <QMainWindow> #include "clinicalprotocolwindow.h" QT_BEGIN_NAMESPACE namespace Ui { class StageOneMain; } QT_END_NAMESPACE class StageOneMain : public QMainWindow { Q_OBJECT public: StageOneMain(QString, QWidget *parent = nullptr); ~StageOneMain(); ClinicalProtocolWindow *clinwindow; QString pLabel; private: Ui::StageOneMain *ui; }; #endif // STAGEONEMAIN_H.cpp
void StageOneMain::on_pushButton_programs_clicked() { this->close(); clinwindow = new ClinicalProtocolWindow(pLabel, nullptr); clinwindow -> setAttribute(Qt::WA_DeleteOnClose); clinwindow -> show(); }and
ClinicalProtocolWindowas follows:#ifndef CLINICALPROTOCOLWINDOW_H #define CLINICALPROTOCOLWINDOW_H #include <QMainWindow> #include "stageonemain.h" namespace Ui { class ClinicalProtocolWindow; } class ClinicalProtocolWindow : public QMainWindow { Q_OBJECT public: explicit ClinicalProtocolWindow(QString, QWidget *parent = nullptr); ~ClinicalProtocolWindow(); QString pLabel; private slots: void on_pushButton_clicked(); private: Ui::ClinicalProtocolWindow *ui; }; #endif // CLINICALPROTOCOLWINDOW_Hand .cpp
#include "clinicalprotocolwindow.h" #include "ui_clinicalprotocolwindow.h" ClinicalProtocolWindow::ClinicalProtocolWindow(QString patientLabel, QWidget *parent) : QMainWindow(parent), ui(new Ui::ClinicalProtocolWindow) { ui->setupUi(this); pLabel = patientLabel; } ClinicalProtocolWindow::~ClinicalProtocolWindow() { delete ui; } void ClinicalProtocolWindow::on_pushButton_clicked() { }I get the errors pointing below
ClinicalProtocolWindow *clinwindow;and the errors are:
stageonemain.h:33: error: C2143: syntax error: missing ';' before '*' stageonemain.h:33: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int stageonemain.h:33: error: C2238: unexpected token(s) preceding ';'It seems that I have overlooked something. I'm feeling frustrated and stuck on this problem.
Can you spot any issues here?
Thanks
@russjohn834 your posted header file is not complete.
-
@russjohn834 your posted header file is not complete.
@JoeCFD Hi, thanks. I just modified it
-
@JoeCFD Hi, thanks. I just modified it
@russjohn834 no line 33. Better to make variables private.
#ifndef STAGEONEMAIN_H #define STAGEONEMAIN_H #include <QMainWindow> QT_BEGIN_NAMESPACE namespace Ui { class StageOneMain; } QT_END_NAMESPACE class ClinicalProtocolWindow; class StageOneMain : public QMainWindow { Q_OBJECT public: StageOneMain(QString, QWidget *parent = nullptr); ~StageOneMain(); private: Ui::StageOneMain *ui{}; ClinicalProtocolWindow *clinwindow{}; QString pLabel; }; #endif // STAGEONEMAIN_H -
Hi,
I'm stuck at debugging an issue.
I have two windows
StageOneMainandClinicalProtocolWindowI want to open
ClinicalProtocolWindowfromStageOneMainand go back.On
StageOneMainI did the following:#ifndef STAGEONEMAIN_H #define STAGEONEMAIN_H #include <QMainWindow> #include "clinicalprotocolwindow.h" QT_BEGIN_NAMESPACE namespace Ui { class StageOneMain; } QT_END_NAMESPACE class StageOneMain : public QMainWindow { Q_OBJECT public: StageOneMain(QString, QWidget *parent = nullptr); ~StageOneMain(); ClinicalProtocolWindow *clinwindow; QString pLabel; private: Ui::StageOneMain *ui; }; #endif // STAGEONEMAIN_H.cpp
void StageOneMain::on_pushButton_programs_clicked() { this->close(); clinwindow = new ClinicalProtocolWindow(pLabel, nullptr); clinwindow -> setAttribute(Qt::WA_DeleteOnClose); clinwindow -> show(); }and
ClinicalProtocolWindowas follows:#ifndef CLINICALPROTOCOLWINDOW_H #define CLINICALPROTOCOLWINDOW_H #include <QMainWindow> #include "stageonemain.h" namespace Ui { class ClinicalProtocolWindow; } class ClinicalProtocolWindow : public QMainWindow { Q_OBJECT public: explicit ClinicalProtocolWindow(QString, QWidget *parent = nullptr); ~ClinicalProtocolWindow(); QString pLabel; private slots: void on_pushButton_clicked(); private: Ui::ClinicalProtocolWindow *ui; }; #endif // CLINICALPROTOCOLWINDOW_Hand .cpp
#include "clinicalprotocolwindow.h" #include "ui_clinicalprotocolwindow.h" ClinicalProtocolWindow::ClinicalProtocolWindow(QString patientLabel, QWidget *parent) : QMainWindow(parent), ui(new Ui::ClinicalProtocolWindow) { ui->setupUi(this); pLabel = patientLabel; } ClinicalProtocolWindow::~ClinicalProtocolWindow() { delete ui; } void ClinicalProtocolWindow::on_pushButton_clicked() { }I get the errors pointing below
ClinicalProtocolWindow *clinwindow;and the errors are:
stageonemain.h:33: error: C2143: syntax error: missing ';' before '*' stageonemain.h:33: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int stageonemain.h:33: error: C2238: unexpected token(s) preceding ';'It seems that I have overlooked something. I'm feeling frustrated and stuck on this problem.
Can you spot any issues here?
Thanks
@russjohn834
You have two.hfiles, each trying to include the other. Each has a "guard".#ifndef STAGEONEMAIN_H #define STAGEONEMAIN_H #include <QMainWindow> #include "clinicalprotocolwindow.h"and
#ifndef CLINICALPROTOCOLWINDOW_H #define CLINICALPROTOCOLWINDOW_H #include <QMainWindow> #include "stageonemain.h"Follow through in your head/on a piece of paper what happens. You will find that when
ClinicalProtocolWindow *clinwindow;in
StageOneMain.his reachedClinicalProtocolWindowclass is not defined. Hence the error messages.Mutual inclusion like this is often a sign a bad design. I suspect it is here. Why should both of these classes need to know al about each other just because you have two windows opening?
Find a way to get round this. Just having
StageOneMain.hgoclass ClinicalProtocolWindow;like that may be enough to break to the dependency/error. Or as it currently standsClinicalProtocolWindowhas no need to includeStageOneMain.h. -
@russjohn834 no line 33. Better to make variables private.
#ifndef STAGEONEMAIN_H #define STAGEONEMAIN_H #include <QMainWindow> QT_BEGIN_NAMESPACE namespace Ui { class StageOneMain; } QT_END_NAMESPACE class ClinicalProtocolWindow; class StageOneMain : public QMainWindow { Q_OBJECT public: StageOneMain(QString, QWidget *parent = nullptr); ~StageOneMain(); private: Ui::StageOneMain *ui{}; ClinicalProtocolWindow *clinwindow{}; QString pLabel; }; #endif // STAGEONEMAIN_H@JoeCFD said in error building a window application:
@russjohn834 no line 33.
I modified the original .h file to show only what I thought would be relevant.
It looks like something silly I'm doing!
What is strange is , I have other windows works fine. The error is only when I added the newClinicalProtocolWindow -
@JoeCFD said in error building a window application:
@russjohn834 no line 33.
I modified the original .h file to show only what I thought would be relevant.
It looks like something silly I'm doing!
What is strange is , I have other windows works fine. The error is only when I added the newClinicalProtocolWindow -
@JoeCFD said in error building a window application:
@russjohn834 no line 33.
I modified the original .h file to show only what I thought would be relevant.
It looks like something silly I'm doing!
What is strange is , I have other windows works fine. The error is only when I added the newClinicalProtocolWindow@russjohn834 as JonB pointed out, you have mutual include in these two header files. Use changes I made in your header and you will be good. Add include header in .cpp files.
-
Hi,
I'm stuck at debugging an issue.
I have two windows
StageOneMainandClinicalProtocolWindowI want to open
ClinicalProtocolWindowfromStageOneMainand go back.On
StageOneMainI did the following:#ifndef STAGEONEMAIN_H #define STAGEONEMAIN_H #include <QMainWindow> #include "clinicalprotocolwindow.h" QT_BEGIN_NAMESPACE namespace Ui { class StageOneMain; } QT_END_NAMESPACE class StageOneMain : public QMainWindow { Q_OBJECT public: StageOneMain(QString, QWidget *parent = nullptr); ~StageOneMain(); ClinicalProtocolWindow *clinwindow; QString pLabel; private: Ui::StageOneMain *ui; }; #endif // STAGEONEMAIN_H.cpp
void StageOneMain::on_pushButton_programs_clicked() { this->close(); clinwindow = new ClinicalProtocolWindow(pLabel, nullptr); clinwindow -> setAttribute(Qt::WA_DeleteOnClose); clinwindow -> show(); }and
ClinicalProtocolWindowas follows:#ifndef CLINICALPROTOCOLWINDOW_H #define CLINICALPROTOCOLWINDOW_H #include <QMainWindow> #include "stageonemain.h" namespace Ui { class ClinicalProtocolWindow; } class ClinicalProtocolWindow : public QMainWindow { Q_OBJECT public: explicit ClinicalProtocolWindow(QString, QWidget *parent = nullptr); ~ClinicalProtocolWindow(); QString pLabel; private slots: void on_pushButton_clicked(); private: Ui::ClinicalProtocolWindow *ui; }; #endif // CLINICALPROTOCOLWINDOW_Hand .cpp
#include "clinicalprotocolwindow.h" #include "ui_clinicalprotocolwindow.h" ClinicalProtocolWindow::ClinicalProtocolWindow(QString patientLabel, QWidget *parent) : QMainWindow(parent), ui(new Ui::ClinicalProtocolWindow) { ui->setupUi(this); pLabel = patientLabel; } ClinicalProtocolWindow::~ClinicalProtocolWindow() { delete ui; } void ClinicalProtocolWindow::on_pushButton_clicked() { }I get the errors pointing below
ClinicalProtocolWindow *clinwindow;and the errors are:
stageonemain.h:33: error: C2143: syntax error: missing ';' before '*' stageonemain.h:33: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int stageonemain.h:33: error: C2238: unexpected token(s) preceding ';'It seems that I have overlooked something. I'm feeling frustrated and stuck on this problem.
Can you spot any issues here?
Thanks
Few things in addition to the circular inclusion/dependency you did with your two classes :
@russjohn834 said in error building a window application:
class ClinicalProtocolWindow : public QMainWindow
I wouldn't make
ClinicalProtocolWindowaQMainWindow-based class unless you really need the toolbars and menus, which come with it.
QWidgetor evenQDialogis better, esp. since you haveQt::WA_DeleteOnCloseset.
For example, create your dialog, fill in/change whatever you want to edit and return to yourmainWindowagain.
(I assume it's gonna be some patient form)@russjohn834 said in error building a window application:
this->close();
clinwindow = new ClinicalProtocolWindow(pLabel, nullptr);
clinwindow -> setAttribute(Qt::WA_DeleteOnClose);
clinwindow -> show();This could easily run into
QApplication:quitOnLastWindowClosedwhen there are no other windows or parent widgets involved and then your app just exits without showing anything.Make sure you have a parent window or change the order of
close()/hide()andshow() -
Few things in addition to the circular inclusion/dependency you did with your two classes :
@russjohn834 said in error building a window application:
class ClinicalProtocolWindow : public QMainWindow
I wouldn't make
ClinicalProtocolWindowaQMainWindow-based class unless you really need the toolbars and menus, which come with it.
QWidgetor evenQDialogis better, esp. since you haveQt::WA_DeleteOnCloseset.
For example, create your dialog, fill in/change whatever you want to edit and return to yourmainWindowagain.
(I assume it's gonna be some patient form)@russjohn834 said in error building a window application:
this->close();
clinwindow = new ClinicalProtocolWindow(pLabel, nullptr);
clinwindow -> setAttribute(Qt::WA_DeleteOnClose);
clinwindow -> show();This could easily run into
QApplication:quitOnLastWindowClosedwhen there are no other windows or parent widgets involved and then your app just exits without showing anything.Make sure you have a parent window or change the order of
close()/hide()andshow() -
R russjohn834 has marked this topic as solved on