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. QList<MyClass> problems to use a Qlist with my Class;
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.9k 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.
  • D Offline
    D Offline
    dcbasso
    wrote on last edited by
    #1

    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!!

    1 Reply Last reply
    0
    • B Offline
      B Offline
      blobfish
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcbasso
        wrote on last edited by
        #3

        Sure, derived from QObject.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dcbasso
          wrote on last edited by
          #4

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

          @
          QList<Sensores*> listaSensores;
          @

          ?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerManu
            wrote on last edited by
            #5

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

            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