connect function caused errors... do you understand why?
-
I have an error when I try to do connect() function,
maybe you can help me to understand my mistake:MainWindow.cpp:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow), m_status(new QLabel), m_console(new Console), m_settings(new SettingsDialog), m_serial(new QSerialPort(this)) . . . m_readData=new ReadData(m_serial, m_console,m_status, m_settings); connect(m_serial, &QSerialPort::readyRead, m_readData, &ReadData::ReadReply); . . . }
ReadData.h:
#ifndef READDATA_H #define READDATA_H #include <QMainWindow> #include "getreplyfunc.h" #include "console.h" class ReadData: public QMainWindow { Q_OBJECT public: ReadData(QSerialPort *serial, Console *console , QLabel * status, SettingsDialog* setting ); ~ReadData(); GetReplyFunc* ReplyFunc; QSerialPort *m_serial; Console * m_console; public slots: QByteArray ReadReply(); }; #endif // READDATA_H
ReadData.cpp:
#include "ReadData.h" ReadData::ReadData(QSerialPort *serial, Console *console , QLabel * status, SettingsDialog* setting,): { ReplyFunc= new GetReplyFunc(serial, status, setting); } ReadData::~ReadData() { delete ReplyFunc; delete m_serial; delete m_console; } QByteArray ReadData::ReadReply() { const QByteArray data = m_serial->readAll(); ReplyFunc->ActiveFunc(data); m_console->putData(data); return data; }
but I have error in ReadData.cpp in the constructor and destructor:
-
I have an error when I try to do connect() function,
maybe you can help me to understand my mistake:MainWindow.cpp:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow), m_status(new QLabel), m_console(new Console), m_settings(new SettingsDialog), m_serial(new QSerialPort(this)) . . . m_readData=new ReadData(m_serial, m_console,m_status, m_settings); connect(m_serial, &QSerialPort::readyRead, m_readData, &ReadData::ReadReply); . . . }
ReadData.h:
#ifndef READDATA_H #define READDATA_H #include <QMainWindow> #include "getreplyfunc.h" #include "console.h" class ReadData: public QMainWindow { Q_OBJECT public: ReadData(QSerialPort *serial, Console *console , QLabel * status, SettingsDialog* setting ); ~ReadData(); GetReplyFunc* ReplyFunc; QSerialPort *m_serial; Console * m_console; public slots: QByteArray ReadReply(); }; #endif // READDATA_H
ReadData.cpp:
#include "ReadData.h" ReadData::ReadData(QSerialPort *serial, Console *console , QLabel * status, SettingsDialog* setting,): { ReplyFunc= new GetReplyFunc(serial, status, setting); } ReadData::~ReadData() { delete ReplyFunc; delete m_serial; delete m_console; } QByteArray ReadData::ReadReply() { const QByteArray data = m_serial->readAll(); ReplyFunc->ActiveFunc(data); m_console->putData(data); return data; }
but I have error in ReadData.cpp in the constructor and destructor:
-
I have an error when I try to do connect() function,
maybe you can help me to understand my mistake:MainWindow.cpp:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow), m_status(new QLabel), m_console(new Console), m_settings(new SettingsDialog), m_serial(new QSerialPort(this)) . . . m_readData=new ReadData(m_serial, m_console,m_status, m_settings); connect(m_serial, &QSerialPort::readyRead, m_readData, &ReadData::ReadReply); . . . }
ReadData.h:
#ifndef READDATA_H #define READDATA_H #include <QMainWindow> #include "getreplyfunc.h" #include "console.h" class ReadData: public QMainWindow { Q_OBJECT public: ReadData(QSerialPort *serial, Console *console , QLabel * status, SettingsDialog* setting ); ~ReadData(); GetReplyFunc* ReplyFunc; QSerialPort *m_serial; Console * m_console; public slots: QByteArray ReadReply(); }; #endif // READDATA_H
ReadData.cpp:
#include "ReadData.h" ReadData::ReadData(QSerialPort *serial, Console *console , QLabel * status, SettingsDialog* setting,): { ReplyFunc= new GetReplyFunc(serial, status, setting); } ReadData::~ReadData() { delete ReplyFunc; delete m_serial; delete m_console; } QByteArray ReadData::ReadReply() { const QByteArray data = m_serial->readAll(); ReplyFunc->ActiveFunc(data); m_console->putData(data); return data; }
but I have error in ReadData.cpp in the constructor and destructor:
@RuWex said in connect function caused errors... do you understand why?:
ReadData::ReadData(QSerialPort *serial, Console *console , QLabel * status, SettingsDialog* setting,):
Not sure exactly why error. But above line ends in
,):
in the code you have pasted and does not in the screenshot. It would not compile with what you have pasted. That means it is not what you actually have/had and we have no confidence what you really might have in your code when you ask questions.In any case, why in the world is
ReadData
inheriting fromQMainWindow
? I would start by getting rid of that.Additionally, although it's not your error, as @JoeCFD says you can't/shouldn't have a slot returning a value.
-
Please show your pro-File or CMakeLists.txt. You don't run moc on the ReadData header file.