QList<MyClass> problems to use a Qlist with my Class;



  • Hello all, I'm trying to use a QList with a class that I created.

    I Make something like this:

    @
    private:
    QList<Sensores> listaSensores;
    @

    @
    Sensores sensor;
    ...
    this->listaSensores.clear();
    this->listaSensores.append( sensor );
    @

    Well When I try to clear or make a append I got some errors:

    @
    In file included from ../SistemaAssistenciaTecnica/bo/respostasolicitacaotabelasensores.h:5:0,
    from ../SistemaAssistenciaTecnica/bo/respostasolicitacaotabelasensores.cpp:1:
    /opt/QtSDK32/Desktop/Qt/4.8.1/gcc/include/QtCore/qobject.h: In copy constructor 'Sensores::Sensores(const Sensores&)':
    ../SistemaAssistenciaTecnica/bo/sensores.h:7:1: instantiated from 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Sensores]'
    /opt/QtSDK32/Desktop/Qt/4.8.1/gcc/include/QtCore/qlist.h:711:9: instantiated from 'void QList<T>::detach_helper(int) [with T = Sensores]'
    /opt/QtSDK32/Desktop/Qt/4.8.1/gcc/include/QtCore/qlist.h:725:5: instantiated from 'void QList<T>::detach_helper() [with T = Sensores]'
    /opt/QtSDK32/Desktop/Qt/4.8.1/gcc/include/QtCore/qlist.h:446:13: instantiated from 'QList<T>& QList<T>::operator=(const QList<T>&) [with T = Sensores]'
    /opt/QtSDK32/Desktop/Qt/4.8.1/gcc/include/QtCore/qlist.h:766:5: instantiated from 'void QList<T>::clear() [with T = Sensores]'
    ../SistemaAssistenciaTecnica/bo/respostasolicitacaotabelasensores.cpp:29:39: instantiated from here
    /opt/QtSDK32/Desktop/Qt/4.8.1/gcc/include/QtCore/qobject.h:333:5: error: 'QObject::QObject(const QObject&)' is private
    ../SistemaAssistenciaTecnica/bo/sensores.h:7:1: error: within this context
    In file included from /opt/QtSDK32/Desktop/Qt/4.8.1/gcc/include/QtCore/qobject.h:50:0,
    from /opt/QtSDK32/Desktop/Qt/4.8.1/gcc/include/QtCore/QObject:1,
    from ../SistemaAssistenciaTecnica/bo/respostasolicitacaotabelasensores.h:4,
    from ../SistemaAssistenciaTecnica/bo/respostasolicitacaotabelasensores.cpp:1:
    /opt/QtSDK32/Desktop/Qt/4.8.1/gcc/include/QtCore/qlist.h: In member function 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Sensores]':
    /opt/QtSDK32/Desktop/Qt/4.8.1/gcc/include/QtCore/qlist.h:399:17: note: synthesized method 'Sensores::Sensores(const Sensores&)' first required here
    make: Leaving directory `/home/dvl/svn/repoBEVSAT/main/src/BalancaEmbarcadaVeicular/compiled32'
    make: *** [respostasolicitacaotabelasensores.o] Error 1
    17:35:18: The process "/usr/bin/make" exited with code 2.
    Error while building project InoveBEV (target: Desktop)
    When executing build step 'Make'
    @

    What I cand do to solve this problem?
    I already have use something similar (QList<int>) and I don't have any problems!!



  • Assuming that the Sensores class is derived from QObject:
    http://qt-project.org/doc/qt-4.8/qobject.html#no-copy-constructor-or-assignment-operator



  • Sure, derived from QObject.



  • Checking if I undestand: I will need to use Pointers:

    @
    QList<Sensores*> listaSensores;
    @

    ?



  • Yep. Be aware that this implies more thinking about memory management.


Log in to reply
 

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