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. Can't compile when using a pointer parameter in a signal/slot

Can't compile when using a pointer parameter in a signal/slot

Scheduled Pinned Locked Moved Unsolved General and Desktop
signal & slotpointer
6 Posts 3 Posters 3.6k 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.
  • K Offline
    K Offline
    kitfox
    wrote on last edited by
    #1

    I have three classes, all of which descend from QObject. My Environment class contains a pointer to an instance of TileDocument. I have a third class called FreePaint which would like to know whenever Enviroment changes its tile document.

    I've declared a documentChanged(TileDocument*) signal in Environment and am attempting to hook it up to a notifyDocumentChanged(TileDocument* doc = 0) slot in FreePaint, but I'm getting a compiler error:

    C:\dev\kitfox.com\game\2015\tilesaurus\build-Tilesaurus-Desktop_Qt_5_5_0_MSVC2013_64bit-Debug\debug\moc_environment.cpp:108: error: C2679: binary '=' : no operator found which takes a right-hand operand of type 'TileDocument *' (or there is no acceptable conversion)
    C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(757): could be 'QString &QString::operator =(const QString::Null &)'
    C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(659): or       'QString &QString::operator =(char)'
    C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(657): or       'QString &QString::operator =(const QByteArray &)'
    C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(655): or       'QString &QString::operator =(const char *)'
    C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(225): or       'QString &QString::operator =(QString &&) throw()'
    C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(222): or       'QString &QString::operator =(QLatin1String)'
    C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(221): or       'QString &QString::operator =(const QString &) throw()'
    C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(220): or       'QString &QString::operator =(QChar)'
    while trying to match the argument list '(QString, TileDocument *)'
    

    This is code that Qt Creator is generating, so I'm not sure what's going on. I've tried running qmake, but that doesn't help.

    What's the right way to set up signals and slots for pointers?

    class Environment : public QObject
    {
        Q_OBJECT
    
        Q_PROPERTY(QString document READ document NOTIFY documentChanged)
    public:
        explicit Environment(QObject *parent = 0);
    
        TileDocument *document() { return m_doc; }
    
        void createDocumentFromImage(const QString &source);
    signals:
        void documentChanged(TileDocument*);
        TileDocument *m_doc;
    };
    
    class FreePaint : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit FreePaint(QWidget *parent = 0);
        ~FreePaint();
    
        void setEnvironment(Environment *env);
    
    public slots:
        void notifyDocumentChanged(TileDocument* doc = 0);
    
    private:
        Environment *m_env;
    };
    void FreePaint::setEnvironment(Environment *env)
    {
        m_env = env;
    
        QObject::connect(env, SIGNAL(documentChanged(TileDocument *)),
    		     this, SLOT(notifyDocumentChanged()));
    
    }
    
    K 1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Should be:

      void FreePaint::setEnvironment(Environment *env)
      {
          m_env = env;
      
          QObject::connect(env, SIGNAL(documentChanged(TileDocument *)),
                   this, SLOT(notifyDocumentChanged(TileDocument *)));
      }
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      1
      • jsulmJ jsulm

        Should be:

        void FreePaint::setEnvironment(Environment *env)
        {
            m_env = env;
        
            QObject::connect(env, SIGNAL(documentChanged(TileDocument *)),
                     this, SLOT(notifyDocumentChanged(TileDocument *)));
        }
        
        K Offline
        K Offline
        kitfox
        wrote on last edited by
        #3

        @jsulm That didn't help. I'm still getting the same error. Also, the docs say that both forms of declaraing the connection should work:
        http://doc.qt.io/qt-5/signalsandslots.html

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Your signal signature doesn't match your property declaration. That's the first thing to correct

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            The error message you get looks like you're trying to assign TileDocument* to a string.
            Can you post more code?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • K kitfox

              I have three classes, all of which descend from QObject. My Environment class contains a pointer to an instance of TileDocument. I have a third class called FreePaint which would like to know whenever Enviroment changes its tile document.

              I've declared a documentChanged(TileDocument*) signal in Environment and am attempting to hook it up to a notifyDocumentChanged(TileDocument* doc = 0) slot in FreePaint, but I'm getting a compiler error:

              C:\dev\kitfox.com\game\2015\tilesaurus\build-Tilesaurus-Desktop_Qt_5_5_0_MSVC2013_64bit-Debug\debug\moc_environment.cpp:108: error: C2679: binary '=' : no operator found which takes a right-hand operand of type 'TileDocument *' (or there is no acceptable conversion)
              C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(757): could be 'QString &QString::operator =(const QString::Null &)'
              C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(659): or       'QString &QString::operator =(char)'
              C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(657): or       'QString &QString::operator =(const QByteArray &)'
              C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(655): or       'QString &QString::operator =(const char *)'
              C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(225): or       'QString &QString::operator =(QString &&) throw()'
              C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(222): or       'QString &QString::operator =(QLatin1String)'
              C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(221): or       'QString &QString::operator =(const QString &) throw()'
              C:\Qt\5.5\msvc2013_64\include\QtCore/qstring.h(220): or       'QString &QString::operator =(QChar)'
              while trying to match the argument list '(QString, TileDocument *)'
              

              This is code that Qt Creator is generating, so I'm not sure what's going on. I've tried running qmake, but that doesn't help.

              What's the right way to set up signals and slots for pointers?

              class Environment : public QObject
              {
                  Q_OBJECT
              
                  Q_PROPERTY(QString document READ document NOTIFY documentChanged)
              public:
                  explicit Environment(QObject *parent = 0);
              
                  TileDocument *document() { return m_doc; }
              
                  void createDocumentFromImage(const QString &source);
              signals:
                  void documentChanged(TileDocument*);
                  TileDocument *m_doc;
              };
              
              class FreePaint : public QWidget
              {
                  Q_OBJECT
              
              public:
                  explicit FreePaint(QWidget *parent = 0);
                  ~FreePaint();
              
                  void setEnvironment(Environment *env);
              
              public slots:
                  void notifyDocumentChanged(TileDocument* doc = 0);
              
              private:
                  Environment *m_env;
              };
              void FreePaint::setEnvironment(Environment *env)
              {
                  m_env = env;
              
                  QObject::connect(env, SIGNAL(documentChanged(TileDocument *)),
              		     this, SLOT(notifyDocumentChanged()));
              
              }
              
              K Offline
              K Offline
              kitfox
              wrote on last edited by
              #6

              @kitfox Figured it out. The Q_PROPERTY in Enviroment had the wrong data type.

              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