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. use of deleted function 'Node::Node(const Node&)'

use of deleted function 'Node::Node(const Node&)'

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 994 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.
  • F Offline
    F Offline
    fT3g0
    wrote on last edited by fT3g0
    #1

    Hello!
    I've come across this bug. Usually it has to do with trying to make a copy of a QObject, and maybe the connect does that, but I'm not sure...
    I've cut down the code as much as possible so it still replicates the error

    //net.h
    
    #ifndef NET_H
    #define NET_H
    
    #include <QObject>
    #include "node.h"
    
    class Net : public QObject
    {
        Q_OBJECT
    public:
        explicit Net(QObject *parent = nullptr);
        void foo();
    
    signals:
        QString requestNodeInfo();
    
    private:
        QVector<Node> node;
    };
    
    #endif // NET_H
    
    //node.h
    
    #ifndef NODE_H
    #define NODE_H
    
    #include <QObject>
    
    class Net;
    
    class Node : public QObject
    {
        Q_OBJECT
    
    public:
        explicit Node(Net *parentNet = nullptr);
    
    public slots:
        QString provideNodeInfo();
    };
    
    #endif // NODE_H
    
    
    //main.cpp
    
    #include <QCoreApplication>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        return a.exec();
    }
    
    
    //net.cpp
    
    #include "net.h"
    
    Net::Net(QObject *parent) : QObject(parent)
    {
    
    }
    
    void Net::foo()
    {
        for (int i=0; i<node.size(); i++)
        {
        connect(this,&Net::requestNodeInfo,&node[i],&Node::provideNodeInfo);
        }
    }
    
    
    //node.cpp
    
    #include "node.h"
    #include "net.h"
    
    Node::Node(Net *parentNet) : QObject(parentNet)
    {
    
    }
    
    QString Node::provideNodeInfo()
    {
    
    }
    
    
    

    The error messages are:
    use of deleted function 'Node::Node(const Node&)'
    'QObject::QObject(const &QObject) is private within this context

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome to the forums :)

      if this line is correct
      QVector<Node> node;
      that is the reason.
      It has to be
      QVector<Node *> node;
      or else it will try to copy the Node into the list. (which is not allowed)
      So the template type must be * (pointer to Node)

      1 Reply Last reply
      4
      • F Offline
        F Offline
        fT3g0
        wrote on last edited by
        #3

        Thank you, had a blind spot there haha!

        mrjjM 1 Reply Last reply
        0
        • F fT3g0

          Thank you, had a blind spot there haha!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @fT3g0
          :) we all know such situations.

          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