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. Compiling a lambda using a signal thinks signal is undefined?
Forum Updated to NodeBB v4.3 + New Features

Compiling a lambda using a signal thinks signal is undefined?

Scheduled Pinned Locked Moved Solved C++ Gurus
2 Posts 2 Posters 233 Views 2 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.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by fcarney
    #1

    In the constructor I define a lambda. That lambda when called needs to trigger a signal defined later in the class. Why would it think it is undefined? The compiler linker does not like this.

    #include <QAbstractProxyModel>
    #include <QAbstractItemModel>
    #include <QModelIndex>
    #include <QFileSystemModel>
    
    #ifndef TABLEPROXYMODEL_H
    #define TABLEPROXYMODEL_H
    
    class FileSystemTableProxyModel : public QAbstractProxyModel
    {
    
        Q_PROPERTY(QAbstractItemModel* model READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
        Q_PROPERTY(QModelIndex rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
    public:
        FileSystemTableProxyModel(){
            connect(this, &QAbstractProxyModel::sourceModelChanged, [this](){
                m_rootIndex = sourceModel()->index(0,0);
                emit rootIndexChanged(m_rootIndex);
            });
        }
    
        QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
        {
            return QVariant();
        }
        QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
        {
            Q_UNUSED(parent)
    
            if(row < 0 || row >= rowCount())
                return QModelIndex();
            if(column < 0 || column >= columnCount())
                return QModelIndex();
    
            return createIndex(row, column);
        }
        QModelIndex parent(const QModelIndex &index) const override
        {
            Q_UNUSED(index)
    
            return QModelIndex();
        }
        int rowCount(const QModelIndex &parent = QModelIndex()) const override
        {
            Q_UNUSED(parent)
    
            return sourceModel()->rowCount(m_rootIndex);
        }
        int columnCount(const QModelIndex &parent = QModelIndex()) const override
        {
            Q_UNUSED(parent)
    
            return 4;
        }
    
        QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
        {
            if(sourceIndex.model() != sourceModel() || !sourceIndex.isValid())
                return QModelIndex();
    
            auto proxyindex = index(sourceIndex.row(), sourceIndex.column());
            if(!proxyindex.isValid())
                return QModelIndex();
    
            return proxyindex;
        }
        QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
        {
            if(proxyIndex.model() != this || !proxyIndex.isValid())
                return QModelIndex();
    
            auto sourceindex = sourceModel()->index(proxyIndex.row(), proxyIndex.column());
            if(!sourceindex.isValid())
                return QModelIndex();
    
            return sourceindex;
        }
    
        QModelIndex rootIndex() const
        {
            return m_rootIndex;
        }
    
    public slots:
        void setRootIndex(QModelIndex rootindex)
        {
            if (m_rootIndex == rootindex)
                return;
    
            if(sourceModel() != rootindex.model())
                return;
    
            m_rootIndex = rootindex;
            emit rootIndexChanged(m_rootIndex);
        }
    
    signals:
        void rootIndexChanged(QModelIndex rootIndex);
    
    private:
    
        QModelIndex m_rootIndex;
    };
    
    #endif // TABLEPROXYMODEL_H
    
    

    Edit:
    The error:

    undefined reference to Makefile:263: recipe for target 'ProxyModelTesting' failed
    `FileSystemTableProxyModel::rootIndexChanged(QModelIndex)'
    collect2: error: ld returned 1 exit status
    

    C++ is a perfectly valid school of magic.

    Chris KawaC 1 Reply Last reply
    0
    • fcarneyF fcarney

      In the constructor I define a lambda. That lambda when called needs to trigger a signal defined later in the class. Why would it think it is undefined? The compiler linker does not like this.

      #include <QAbstractProxyModel>
      #include <QAbstractItemModel>
      #include <QModelIndex>
      #include <QFileSystemModel>
      
      #ifndef TABLEPROXYMODEL_H
      #define TABLEPROXYMODEL_H
      
      class FileSystemTableProxyModel : public QAbstractProxyModel
      {
      
          Q_PROPERTY(QAbstractItemModel* model READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
          Q_PROPERTY(QModelIndex rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
      public:
          FileSystemTableProxyModel(){
              connect(this, &QAbstractProxyModel::sourceModelChanged, [this](){
                  m_rootIndex = sourceModel()->index(0,0);
                  emit rootIndexChanged(m_rootIndex);
              });
          }
      
          QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
          {
              return QVariant();
          }
          QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
          {
              Q_UNUSED(parent)
      
              if(row < 0 || row >= rowCount())
                  return QModelIndex();
              if(column < 0 || column >= columnCount())
                  return QModelIndex();
      
              return createIndex(row, column);
          }
          QModelIndex parent(const QModelIndex &index) const override
          {
              Q_UNUSED(index)
      
              return QModelIndex();
          }
          int rowCount(const QModelIndex &parent = QModelIndex()) const override
          {
              Q_UNUSED(parent)
      
              return sourceModel()->rowCount(m_rootIndex);
          }
          int columnCount(const QModelIndex &parent = QModelIndex()) const override
          {
              Q_UNUSED(parent)
      
              return 4;
          }
      
          QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
          {
              if(sourceIndex.model() != sourceModel() || !sourceIndex.isValid())
                  return QModelIndex();
      
              auto proxyindex = index(sourceIndex.row(), sourceIndex.column());
              if(!proxyindex.isValid())
                  return QModelIndex();
      
              return proxyindex;
          }
          QModelIndex mapToSource(const QModelIndex &proxyIndex) const override
          {
              if(proxyIndex.model() != this || !proxyIndex.isValid())
                  return QModelIndex();
      
              auto sourceindex = sourceModel()->index(proxyIndex.row(), proxyIndex.column());
              if(!sourceindex.isValid())
                  return QModelIndex();
      
              return sourceindex;
          }
      
          QModelIndex rootIndex() const
          {
              return m_rootIndex;
          }
      
      public slots:
          void setRootIndex(QModelIndex rootindex)
          {
              if (m_rootIndex == rootindex)
                  return;
      
              if(sourceModel() != rootindex.model())
                  return;
      
              m_rootIndex = rootindex;
              emit rootIndexChanged(m_rootIndex);
          }
      
      signals:
          void rootIndexChanged(QModelIndex rootIndex);
      
      private:
      
          QModelIndex m_rootIndex;
      };
      
      #endif // TABLEPROXYMODEL_H
      
      

      Edit:
      The error:

      undefined reference to Makefile:263: recipe for target 'ProxyModelTesting' failed
      `FileSystemTableProxyModel::rootIndexChanged(QModelIndex)'
      collect2: error: ld returned 1 exit status
      
      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @fcarney You're missing Q_OBJECT macro so moc did not generate signal's body.

      Unrelated - You should use const QModelIndex& parameters and make your signals const.

      1 Reply Last reply
      2

      • Login

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