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. Complicated system design - need your help!!
Forum Updated to NodeBB v4.3 + New Features

Complicated system design - need your help!!

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++h file
12 Posts 6 Posters 678 Views 1 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
    RuWex
    wrote on last edited by RuWex
    #1

    sendCommand.h:

    #ifndef SENDCOMMANDS_H
    #define SENDCOMMANDS_H
    
    #include <QString>
    #include <QSerialPort>
    //#include <QPlainTextEdit>
    
    #include "DoAdditionalTest.h"
    #include "ReadDataFromCamera.h"
    
    class SettingsDialog;
    
    class SendCommands
    {
    public:
        SendCommands(QSerialPort*, QLabel *, SettingsDialog *);
        ~SendCommands();
        void StartToSendCommand(QString fileName);
        void GetReplyFromCamera(QString line);
        void IsReplyRight(QString res, QString com);
        void GetReply(QByteArray letter);
    
        QSerialPort *m_serial;
        QLabel* m_status;
        SettingsDialog *m_settings;
        ReadDataFromCamera * m_read;
        //MainWindow *main_;
    
    
    private:
        DoAdditionalTest* additionalTest=nullptr;
        void showStatusMessage(const QString &message);
        QString m_line;
        int m_i, m_index;
        QString m_command;
        QByteArray m_reply, m_lastLetter="";
        bool m_ok=false;
        //QTimer * timer;
    
    };
    
    #endif // SENDCOMMANDS_H
    

    ReadDataFromCamera.h:

    #ifndef READDATA_H
    #define READDATA_H
    #include <QMainWindow>
    #include "settingsdialog.h"
    #include "getreplyfunc.h"
    #include "console.h"
    
    class ReadDataFromCamera: public QMainWindow
    {
    
        Q_OBJECT
    
    public:
        ReadDataFromCamera(QSerialPort *serial ,  QLabel * status, SettingsDialog* setting );
        ~ReadDataFromCamera();
        GetReplyFunc* ReplyFunc;
        QSerialPort *m_serial;
        Console * m_console;
    
    public slots:
        QByteArray ReadReply();
    
    };
    
    #endif // READDATA_H
    
    

    GetReplyFunc.h:

    #ifndef GETREPLYFUNC_H
    #define GETREPLYFUNC_H
    #include "SendCommands.h"
    
    
    class GetReplyFunc
    {
    public:
        GetReplyFunc(QSerialPort * serialPo, QLabel * status, SettingsDialog* setting);
        void ActiveFunc(QByteArray data);
        SendCommands* send;
    
    };
    
    #endif // GETREPLYFUNC_H
    
    

    I have many errors:
    -C:\Users\ruthw\Desktop\class cat\getreplyfunc.h:11: error: 'SendCommands' does not name a type
    SendCommands* send;
    ^~~~~~~~~~~~

    -C:\Users\ruthw\Desktop\class cat\SendCommands.h:26: error: 'ReadDataFromCamera' does not name a type
    ReadDataFromCamera * m_read;
    ^~~~~~~~~~~~~~~~~~

    -C:\Users\ruthw\Desktop\class cat\getreplyfunc.h:11: error: 'SendCommands' does not name a type; did you mean 'mciSendCommand'?
    SendCommands* send;
    ^~~~~~~~~~~~

     mciSendCommand
    

    -C:\Users\ruthw\Desktop\class cat\getreplyfunc.h:11: error: 'SendCommands' does not name a type; did you mean 'mciSendCommand'?
    SendCommands* send;
    ^~~~~~~~~~~~

     mciSendCommand
    

    -C:\Users\ruthw\Desktop\class cat\SendCommands.h:26: error: 'ReadDataFromCamera' does not name a type
    ReadDataFromCamera * m_read;
    ^~~~~~~~~~~~~~~~~~

    error1.PNG error2.PNG
    alt texterror1.PNG

    error2.PNGalt text

    jsulmJ 1 Reply Last reply
    0
    • R Offline
      R Offline
      RuWex
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • R RuWex

        sendCommand.h:

        #ifndef SENDCOMMANDS_H
        #define SENDCOMMANDS_H
        
        #include <QString>
        #include <QSerialPort>
        //#include <QPlainTextEdit>
        
        #include "DoAdditionalTest.h"
        #include "ReadDataFromCamera.h"
        
        class SettingsDialog;
        
        class SendCommands
        {
        public:
            SendCommands(QSerialPort*, QLabel *, SettingsDialog *);
            ~SendCommands();
            void StartToSendCommand(QString fileName);
            void GetReplyFromCamera(QString line);
            void IsReplyRight(QString res, QString com);
            void GetReply(QByteArray letter);
        
            QSerialPort *m_serial;
            QLabel* m_status;
            SettingsDialog *m_settings;
            ReadDataFromCamera * m_read;
            //MainWindow *main_;
        
        
        private:
            DoAdditionalTest* additionalTest=nullptr;
            void showStatusMessage(const QString &message);
            QString m_line;
            int m_i, m_index;
            QString m_command;
            QByteArray m_reply, m_lastLetter="";
            bool m_ok=false;
            //QTimer * timer;
        
        };
        
        #endif // SENDCOMMANDS_H
        

        ReadDataFromCamera.h:

        #ifndef READDATA_H
        #define READDATA_H
        #include <QMainWindow>
        #include "settingsdialog.h"
        #include "getreplyfunc.h"
        #include "console.h"
        
        class ReadDataFromCamera: public QMainWindow
        {
        
            Q_OBJECT
        
        public:
            ReadDataFromCamera(QSerialPort *serial ,  QLabel * status, SettingsDialog* setting );
            ~ReadDataFromCamera();
            GetReplyFunc* ReplyFunc;
            QSerialPort *m_serial;
            Console * m_console;
        
        public slots:
            QByteArray ReadReply();
        
        };
        
        #endif // READDATA_H
        
        

        GetReplyFunc.h:

        #ifndef GETREPLYFUNC_H
        #define GETREPLYFUNC_H
        #include "SendCommands.h"
        
        
        class GetReplyFunc
        {
        public:
            GetReplyFunc(QSerialPort * serialPo, QLabel * status, SettingsDialog* setting);
            void ActiveFunc(QByteArray data);
            SendCommands* send;
        
        };
        
        #endif // GETREPLYFUNC_H
        
        

        I have many errors:
        -C:\Users\ruthw\Desktop\class cat\getreplyfunc.h:11: error: 'SendCommands' does not name a type
        SendCommands* send;
        ^~~~~~~~~~~~

        -C:\Users\ruthw\Desktop\class cat\SendCommands.h:26: error: 'ReadDataFromCamera' does not name a type
        ReadDataFromCamera * m_read;
        ^~~~~~~~~~~~~~~~~~

        -C:\Users\ruthw\Desktop\class cat\getreplyfunc.h:11: error: 'SendCommands' does not name a type; did you mean 'mciSendCommand'?
        SendCommands* send;
        ^~~~~~~~~~~~

         mciSendCommand
        

        -C:\Users\ruthw\Desktop\class cat\getreplyfunc.h:11: error: 'SendCommands' does not name a type; did you mean 'mciSendCommand'?
        SendCommands* send;
        ^~~~~~~~~~~~

         mciSendCommand
        

        -C:\Users\ruthw\Desktop\class cat\SendCommands.h:26: error: 'ReadDataFromCamera' does not name a type
        ReadDataFromCamera * m_read;
        ^~~~~~~~~~~~~~~~~~

        error1.PNG error2.PNG
        alt texterror1.PNG

        error2.PNGalt text

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @RuWex Please post the very first error...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        R 1 Reply Last reply
        1
        • jsulmJ jsulm

          @RuWex Please post the very first error...

          R Offline
          R Offline
          RuWex
          wrote on last edited by
          #4

          @jsulm
          C:\Users\ruthw\Desktop\class cat\getreplyfunc.h:11: error: 'SendCommands' does not name a type; did you mean 'QUndoCommand'?
          SendCommands* send;
          ^~~~~~~~~~~~
          QUndoCommand

          JonBJ 1 Reply Last reply
          0
          • R RuWex

            @jsulm
            C:\Users\ruthw\Desktop\class cat\getreplyfunc.h:11: error: 'SendCommands' does not name a type; did you mean 'QUndoCommand'?
            SendCommands* send;
            ^~~~~~~~~~~~
            QUndoCommand

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

            @RuWex
            SendCommands.h includes ReadDataFromCamera.h before it defines class SendCommands. ReadDataFromCamera.h includes getreplyfunc.h. GetReplyFunc.h first includes SendCommands.h: --- whose content will not be processed as you are already inside that header file already --- and then references SendCommands* send. SendCommands is not yet defined there, hence the error message(s).

            Sort out your includes and their ordering. You should not have this kind of cross-includes going on, partly because it won't compile but also because presumably the logic won't make sense for who includes whom --- there should be no need for circular includes like this, work out who depends on whom and try to write code which does not have such inclusion.

            R 1 Reply Last reply
            1
            • JonBJ JonB

              @RuWex
              SendCommands.h includes ReadDataFromCamera.h before it defines class SendCommands. ReadDataFromCamera.h includes getreplyfunc.h. GetReplyFunc.h first includes SendCommands.h: --- whose content will not be processed as you are already inside that header file already --- and then references SendCommands* send. SendCommands is not yet defined there, hence the error message(s).

              Sort out your includes and their ordering. You should not have this kind of cross-includes going on, partly because it won't compile but also because presumably the logic won't make sense for who includes whom --- there should be no need for circular includes like this, work out who depends on whom and try to write code which does not have such inclusion.

              R Offline
              R Offline
              RuWex
              wrote on last edited by
              #6

              @JonB thank you!!
              my problem is that I have a function that called from sendCommand file and also the function called a function from sendCommand....
              I have to do that, so in order to solve the problem I did classes casing to solve the The circularity problem...
              do you have any advice for me?

              Christian EhrlicherC JonBJ 2 Replies Last reply
              0
              • R RuWex

                @JonB thank you!!
                my problem is that I have a function that called from sendCommand file and also the function called a function from sendCommand....
                I have to do that, so in order to solve the problem I did classes casing to solve the The circularity problem...
                do you have any advice for me?

                Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @RuWex said in I have strange errors in my h files:

                I have to do that, so in order to solve the problem I did classes casing to solve the The circularity problem...
                do you have any advice for me?

                Hint: Forward declare class

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • R RuWex

                  @JonB thank you!!
                  my problem is that I have a function that called from sendCommand file and also the function called a function from sendCommand....
                  I have to do that, so in order to solve the problem I did classes casing to solve the The circularity problem...
                  do you have any advice for me?

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

                  @RuWex
                  No, because I don't understand what logic you are using to write your classes as you have done, and I doubt you will be able to explain in words I can understand.

                  You should tidy the logic of your code. You should keep UI stuff quite separate from backend stuff. For example, GetReplyFunc should have no need to be passed a QLabel or a SettingsDialog. SendCommands similarly. SendCommands includes ReadDataFromCamera which includes GetReplyFunc which includes SendCommands. Something there makes no sense. Separate out your classes. I don't know what you are passing around UI elements like labels and dialogs for, at least some of your stuff should be implemented via signals and slots in Qt.

                  R 1 Reply Last reply
                  3
                  • JonBJ JonB

                    @RuWex
                    No, because I don't understand what logic you are using to write your classes as you have done, and I doubt you will be able to explain in words I can understand.

                    You should tidy the logic of your code. You should keep UI stuff quite separate from backend stuff. For example, GetReplyFunc should have no need to be passed a QLabel or a SettingsDialog. SendCommands similarly. SendCommands includes ReadDataFromCamera which includes GetReplyFunc which includes SendCommands. Something there makes no sense. Separate out your classes. I don't know what you are passing around UI elements like labels and dialogs for, at least some of your stuff should be implemented via signals and slots in Qt.

                    R Offline
                    R Offline
                    RuWex
                    wrote on last edited by
                    #9

                    @JonB I will try if you dont care to explain you what I need to do and why it is so complicated to me...
                    I need to read commands from file and send them by terminal to USB and then it send it to camera.
                    each line in the file is command
                    after each line I should get from the camera by the USB response, check if its good and to make a doc with Documentation about the process.
                    so, I did everything but 2 thing I dont know how to solve:

                    1. I will describe how its work:
                      sendCommand-> ReadData->RecieveReply->sendCommand->readData.....

                    sendCommand- read the command(line from file) and send it to the camera
                    ReadData-> after the command send I should get a response from the camera so ReadData class response to that.
                    RecieveReply- processes the data(if the response right ang etc...) and then continue the procrss and reading the next command until the commands file get to the end.

                    my problem is how to plan the program, because if you noticed there is The circularity problem!!
                    I complicated which classes to do, the included and everything:|(
                    I dont secceed to solve that problem, and I tried many kinds of desighn...

                    1. I have afetr I send the command to wait to get the response from the camera and just after that to continue send the next command,I dont succeed to do that...
                      if anyone here would be able to help me I would truly appreciate it from the bottom of my heart!
                    1 Reply Last reply
                    0
                    • JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by JoeCFD
                      #10

                      @RuWex said in Complicated system design - need your help!!:

                      QString m_command;
                      QByteArray m_reply, m_lastLetter="";
                      bool m_ok=false;
                      //QTimer * timer;
                      

                      };

                      #endif // SENDCOMMANDS_H

                      Your code is a bit messy. Make your project consistent.

                      1. if you define names of your header files with lower cases. Then do it for all header files.
                      2. sendCommand.h includes "ReadDataFromCamera.h",
                        ReadDataFromCamera.h includes getreplyfunc.h
                        getreplyfunc.h includes "SendCommands.h" or "sendCommands.h"
                        this will not work.
                      3. I have changed your code for compiling.
                      
                      sendCommand.h:
                      
                      #ifndef SENDCOMMANDS_H
                      #define SENDCOMMANDS_H
                      
                      #include <QString>
                      #include <QSerialPort>
                      //#include <QPlainTextEdit>
                      
                      #include "DoAdditionalTest.h"
                      
                      class ReadDataFromCamera;
                      class SettingsDialog;
                      
                      class SendCommands
                      {
                      public:
                          SendCommands(QSerialPort*, QLabel *, SettingsDialog *);
                          ~SendCommands();
                          void StartToSendCommand(QString fileName);
                          void GetReplyFromCamera(QString line);
                          void IsReplyRight(QString res, QString com);
                          void GetReply(QByteArray letter);
                      
                          QSerialPort *m_serial{};
                          QLabel* m_status{};
                          SettingsDialog *m_settings{};
                          ReadDataFromCamera * m_read{};
                          //MainWindow *main_{};
                      
                      
                      private:
                          DoAdditionalTest* additionalTest=nullptr;
                          void showStatusMessage(const QString &message);
                          QString m_line;
                          int m_i, m_index;
                          QString m_command;
                          QByteArray m_reply, m_lastLetter="";
                          bool m_ok=false;
                          //QTimer * timer;
                      
                      };
                      
                      #endif // SENDCOMMANDS_H
                      
                      #ifndef READDATA_H
                      #define READDATA_H
                      #include <QMainWindow>
                      #include "settingsdialog.h"
                      #include "console.h"
                      
                      class GetReplyFunc;
                      
                      class ReadDataFromCamera: public QMainWindow
                      {
                      
                          Q_OBJECT
                      
                      public:
                          ReadDataFromCamera(QSerialPort *serial ,  QLabel * status, SettingsDialog* setting );
                          ~ReadDataFromCamera();
                          GetReplyFunc* ReplyFunc{};
                          QSerialPort *m_serial{};
                          Console * m_console{};
                      
                      public slots:
                          QByteArray ReadReply();
                      
                      };
                      
                      #endif // READDATA_H
                      
                      #ifndef GETREPLYFUNC_H
                      #define GETREPLYFUNC_H
                      
                      
                      class SendCommands;
                      
                      class GetReplyFunc
                      {
                      public:
                          GetReplyFunc(QSerialPort * serialPo, QLabel * status, SettingsDialog* setting);
                          void ActiveFunc(QByteArray data);
                          SendCommands* send{};
                      
                      };
                      
                      #endif // GETREPLYFUNC_H
                      
                      
                      
                      

                      include these headers in the cpp files.

                      1 Reply Last reply
                      2
                      • JoeCFDJ Offline
                        JoeCFDJ Offline
                        JoeCFD
                        wrote on last edited by JoeCFD
                        #11

                        Do not forget to initialize your pointers with nullptr. I did it for you as well.

                        1 Reply Last reply
                        1
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Hi,

                          As @JonB already explained you need to properly encapsulate the various aspects of your logic.

                          One class to handle the communication with the camera. That class shall not care at all about the UI. That's not its job. It should provide feedback through signals. What is connect to it, again, not its problem.

                          The job of your UI is to give the user the option to load a file and configure stuff. The UI will be responsible for reconfiguring whatever needs to be.

                          As for the sequential command handling, load the file, parse it, send the first command and once your "communicator" class is done with it, make it emit a signal to signify that the task is done. In a slot connected to that signal, send the next command.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          2

                          • Login

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