New class



  • Hi all !

    I try to create a new class called Sms.
    You can see sms.h :

    #ifndef SMS_H
    #define SMS_H
    
    #include <QObject>
    
    #include <QDateTime>
    #include <QString>
    
    class Sms : public QObject
    {
        Q_OBJECT
    public:
        explicit Sms(QObject *parent = 0);
        explicit Sms(QString num, QDateTime dt, QString msg = QString());
        explicit Sms(QString num, QString msg, QDateTime dt = QDateTime());
    
        ~Sms();
    
        inline void setNum(QString num){ m_num = num; }
        inline void setDt(QDateTime dt){ m_dt = dt; }
        inline void setMsg(QString msg){ m_message = msg; }
    
        inline QString num(){ return m_num; }
        inline QDateTime dt(){ return m_dt; }
        inline QString message(){ return m_message; }
    
    signals:
    
    public slots:
    
    protected:
        QString m_num;
        QDateTime m_dt;
        QString m_message;
    };
    
    #endif // SMS_H
    

    And you can see sms.cpp :

    #include "sms.h"
    
    Sms::Sms(QObject *parent) : QObject(parent)
    {
    
    }
    
    Sms::Sms(QString num, QDateTime dt, QString msg) :
        QObject(NULL),
        m_num(num),
        m_dt(dt),
        m_message(msg){
    
    }
    
    Sms::Sms(QString num, QString msg, QDateTime dt) :
        QObject(NULL),
        m_num(num),
        m_dt(dt),
        m_message(msg)
    {
    
    }
    
    Sms::~Sms(){
    
    }
    

    I would like to used this class like this :

    function(Sms(QString("num"),"message"));
    

    But, I get this error :

    erreur : use of deleted function ‘Sms::Sms(const Sms&)’
                     sendSMS(Sms(m_messageInfo.at(2),"PONG"));
                                                            ^
    

    Can someone help me to do this ?

    Thank a lot.



  • the problem is not with Sms but with function.

    You can't have function(Sms a) it must either be by reference (function(const Sms& a) or pointer (function(Sms* a))

    Alternatively, since you are not using any feature from QObject from what I can see, you can just get rid of the QObject inheritance



  • Thank a lot !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.