Unsolved Complicated system design - need your help!!
-
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;
^~~~~~~~~~~~~~~~~~
-
This post is deleted! -
@RuWex Please post the very first error...
-
@jsulm
C:\Users\ruthw\Desktop\class cat\getreplyfunc.h:11: error: 'SendCommands' does not name a type; did you mean 'QUndoCommand'?
SendCommands* send;
^~~~~~~~~~~~
QUndoCommand -
@RuWex
SendCommands.h
includesReadDataFromCamera.h
before it definesclass SendCommands
.ReadDataFromCamera.h
includesgetreplyfunc.h
.GetReplyFunc.h
first includesSendCommands.h:
--- whose content will not be processed as you are already inside that header file already --- and then referencesSendCommands* 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.
-
@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? -
@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
-
@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 aQLabel
or aSettingsDialog
.SendCommands
similarly.SendCommands
includesReadDataFromCamera
which includesGetReplyFunc
which includesSendCommands
. 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. -
@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:- 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...- 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!
- I will describe how its work:
-
@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.
- if you define names of your header files with lower cases. Then do it for all header files.
- sendCommand.h includes "ReadDataFromCamera.h",
ReadDataFromCamera.h includes getreplyfunc.h
getreplyfunc.h includes "SendCommands.h" or "sendCommands.h"
this will not work. - 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.
-
Do not forget to initialize your pointers with nullptr. I did it for you as well.
-
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.