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. connect function caused errors... do you understand why?
Forum Updated to NodeBB v4.3 + New Features

connect function caused errors... do you understand why?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 324 Views
  • 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
    #1

    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:
    Capture.PNG

    Capture.PNG

    R JonBJ 2 Replies Last reply
    0
    • R Offline
      R Offline
      RuWex
      wrote on last edited by
      #6

      @JoeCFD @JonB @Christian-Ehrlicher
      thank you:)
      I found my problem that ReadData is function in QMainWindow so I just changed the name of the function
      and @JonB I paste the code and deleted the Irrelevant lines so maybe its a mistake, sorry:(

      1 Reply Last reply
      0
      • R RuWex

        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:
        Capture.PNG

        Capture.PNG

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

        @RuWex anyone?

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #3

          @RuWex said in connect function caused errors... do you understand why?:

          QByteArray ReadReply();

          QByteArray ReadReply(); slot can not return things.

          1 Reply Last reply
          0
          • R RuWex

            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:
            Capture.PNG

            Capture.PNG

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

            @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 from QMainWindow? 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.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Please show your pro-File or CMakeLists.txt. You don't run moc on the ReadData header file.

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

                @JoeCFD @JonB @Christian-Ehrlicher
                thank you:)
                I found my problem that ReadData is function in QMainWindow so I just changed the name of the function
                and @JonB I paste the code and deleted the Irrelevant lines so maybe its a mistake, sorry:(

                1 Reply Last reply
                0

                • Login

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