Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. New class
Qt 6.11 is out! See what's new in the release blog

New class

Scheduled Pinned Locked Moved Solved C++ Gurus
3 Posts 2 Posters 1.7k 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.
  • A Offline
    A Offline
    Arthux
    wrote on last edited by Arthux
    #1

    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.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • A Offline
        A Offline
        Arthux
        wrote on last edited by
        #3

        Thank a lot !

        1 Reply Last reply
        1

        • Login

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