Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error building a window application
Qt 6.11 is out! See what's new in the release blog

error building a window application

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 902 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    russjohn834
    wrote on last edited by russjohn834
    #1

    Hi,

    I'm stuck at debugging an issue.

    I have two windows StageOneMain and ClinicalProtocolWindow

    I want to open ClinicalProtocolWindow from StageOneMain and go back.

    On StageOneMain I 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 ClinicalProtocolWindow as 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_H
    

    and .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

    JoeCFDJ JonBJ Pl45m4P 3 Replies Last reply
    0
    • R russjohn834

      Hi,

      I'm stuck at debugging an issue.

      I have two windows StageOneMain and ClinicalProtocolWindow

      I want to open ClinicalProtocolWindow from StageOneMain and go back.

      On StageOneMain I 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 ClinicalProtocolWindow as 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_H
      

      and .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

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @russjohn834 your posted header file is not complete.

      R 1 Reply Last reply
      1
      • JoeCFDJ JoeCFD

        @russjohn834 your posted header file is not complete.

        R Offline
        R Offline
        russjohn834
        wrote on last edited by
        #3

        @JoeCFD Hi, thanks. I just modified it

        JoeCFDJ 1 Reply Last reply
        0
        • R russjohn834

          @JoeCFD Hi, thanks. I just modified it

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          @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
          
          R 1 Reply Last reply
          1
          • R russjohn834

            Hi,

            I'm stuck at debugging an issue.

            I have two windows StageOneMain and ClinicalProtocolWindow

            I want to open ClinicalProtocolWindow from StageOneMain and go back.

            On StageOneMain I 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 ClinicalProtocolWindow as 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_H
            

            and .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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @russjohn834
            You have two .h files, 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.h is reached ClinicalProtocolWindow class 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.h go class ClinicalProtocolWindow; like that may be enough to break to the dependency/error. Or as it currently stands ClinicalProtocolWindow has no need to include StageOneMain.h.

            1 Reply Last reply
            2
            • JoeCFDJ JoeCFD

              @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
              
              R Offline
              R Offline
              russjohn834
              wrote on last edited by
              #6

              @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 new ClinicalProtocolWindow

              JonBJ JoeCFDJ 2 Replies Last reply
              0
              • R russjohn834

                @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 new ClinicalProtocolWindow

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @russjohn834
                If you read my answer it will tell you why.
                And if you look at @JoeCFD's code you will see he has inserted

                class ClinicalProtocolWindow;
                

                and removed #include "clinicalprotocolwindow.h". Which will make it compilable.

                1 Reply Last reply
                1
                • R russjohn834

                  @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 new ClinicalProtocolWindow

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by JoeCFD
                  #8

                  @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.

                  1 Reply Last reply
                  1
                  • R russjohn834

                    Hi,

                    I'm stuck at debugging an issue.

                    I have two windows StageOneMain and ClinicalProtocolWindow

                    I want to open ClinicalProtocolWindow from StageOneMain and go back.

                    On StageOneMain I 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 ClinicalProtocolWindow as 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_H
                    

                    and .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

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #9

                    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 ClinicalProtocolWindow a QMainWindow-based class unless you really need the toolbars and menus, which come with it.
                    QWidget or even QDialog is better, esp. since you have Qt::WA_DeleteOnClose set.
                    For example, create your dialog, fill in/change whatever you want to edit and return to your mainWindow again.
                    (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:quitOnLastWindowClosed when there are no other windows or parent widgets involved and then your app just exits without showing anything.

                    • https://doc.qt.io/qt-6/qguiapplication.html#quitOnLastWindowClosed-prop

                    Make sure you have a parent window or change the order of close() / hide() and show()


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    R 1 Reply Last reply
                    3
                    • Pl45m4P Pl45m4

                      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 ClinicalProtocolWindow a QMainWindow-based class unless you really need the toolbars and menus, which come with it.
                      QWidget or even QDialog is better, esp. since you have Qt::WA_DeleteOnClose set.
                      For example, create your dialog, fill in/change whatever you want to edit and return to your mainWindow again.
                      (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:quitOnLastWindowClosed when there are no other windows or parent widgets involved and then your app just exits without showing anything.

                      • https://doc.qt.io/qt-6/qguiapplication.html#quitOnLastWindowClosed-prop

                      Make sure you have a parent window or change the order of close() / hide() and show()

                      R Offline
                      R Offline
                      russjohn834
                      wrote on last edited by
                      #10

                      @Pl45m4 , @JonB , @JoeCFD Many thanks for your feedback :)

                      1 Reply Last reply
                      0
                      • R russjohn834 has marked this topic as solved on

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved