Results 1 to 4 of 4

Thread: Copying QList

  1. #1
    Join Date
    Sep 2009
    Location
    Belgrade, Serbia
    Posts
    40
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Copying QList

    Ok. I have a class.

    Qt Code:
    1. class Material : public QObject
    2. {
    3. public:
    4. Material(QObject *parent = 0);
    5.  
    6. protected:
    7. int m_count;
    8. QString m_fisName;
    9. QString m_fisCode;
    10. QString m_name;
    11. QString m_nameAux;
    12. };
    To copy to clipboard, switch view to plain text mode 

    I made a typedef

    Qt Code:
    1. typedef QList<Material> MaterialList;
    To copy to clipboard, switch view to plain text mode 

    I have another class

    Qt Code:
    1. class RegularOrder : public Order
    2. {
    3. public:
    4. RegularOrder(QObject *parent = 0);
    5.  
    6. void TwinList(MaterialList twinList);
    7. void P3110List(MaterialList p3110List);
    8. void CPSList(MaterialList cpsList);
    9. void KernList(MaterialList kernList);
    10. void BurhList(MaterialList burhList);
    11. void ManualList(MaterialList manualList);
    12.  
    13. protected:
    14. QList<Template> m_templateList;
    15. int m_currentTemplateIndex;
    16.  
    17. UseFlag m_listFlag;
    18. int m_listCount;
    19. QString m_deliveryWhole;
    20.  
    21. MaterialList m_twinList;
    22. MaterialList m_p3110List;
    23. MaterialList m_cpsList;
    24. MaterialList m_kernList;
    25. MaterialList m_burhList;
    26. MaterialList m_manualList;
    27.  
    28. QList<JobProperties> m_jobPropertiesList;
    29. };
    To copy to clipboard, switch view to plain text mode 

    which is so far implemented like this

    Qt Code:
    1. RegularOrder::RegularOrder(QObject *parent) : Order(parent)
    2. {
    3. }
    4.  
    5. void RegularOrder::TwinList(MaterialList twinList)
    6. {
    7. m_twinList = twinList;
    8. }
    9.  
    10. void RegularOrder::P3110List(MaterialList p3110List)
    11. {
    12. m_p3110List = p3110List;
    13. }
    14.  
    15. void RegularOrder::CPSList(MaterialList cpsList)
    16. {
    17. m_cpsList = cpsList;
    18. }
    19.  
    20. void RegularOrder::KernList(MaterialList kernList)
    21. {
    22. m_kernList = kernList;
    23. }
    24.  
    25. void RegularOrder::BurhList(MaterialList burhList)
    26. {
    27. m_burhList = burhList;
    28. }
    29.  
    30. void RegularOrder::ManualList(MaterialList manualList)
    31. {
    32. m_manualList = manualList;
    33. }
    To copy to clipboard, switch view to plain text mode 

    When I try to compile I get the following messages:

    /home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.cpp:1: In file included from woidl.cpp:1:
    /home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.h:14: instantiated from ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Telekom::WorkOrder::Material]’
    /home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.h:14: instantiated from ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Telekom::WorkOrder::Material]’
    /home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.h:14: instantiated from ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Telekom::WorkOrder::Material]’
    /home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.h:14: instantiated from ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Telekom::WorkOrder::Material]’
    /home/ivan/Development/Qt/Radni Nalog/WorkOrder/woidl.h:14: instantiated from ‘void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = Telekom::WorkOrder::Material]’

    Basically the compile stops at the m_twinList = twinList line of code. I read somewhere that QObject can't be used as a reference and copied as normal because of something but honestly didn't understand it completely.

    I solved the problem by removing the inheritance of QObject in Material class. I made it independent. Now I only sort of needed that because I could make some other object a parent of the material class instances so I would have to worry about deleting it. My program will work just fine with out this parenting because only RegularOrder class will be instantiated and only RegularOrder class will need a parent to look after it. But could somebody explain to me what exactly happened here so I know for the future.

    Thanks.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Copying QList

    Check the documentation for Q_DISABLE_COPY 'Instances of subclasses of QObject should not be thought of as values that can be copied or assigned, but as unique identities.'

    Whether or not this is why you are getting the error I don't know, I just remember reading it.

  3. #3
    Join Date
    Sep 2009
    Location
    Belgrade, Serbia
    Posts
    40
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Copying QList

    Well I found some explanations in the QObject documentation. Now it is clearer to me what I tried to do and why it didn't work that way.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Copying QList

    You don't need Material to be a QObject anyway, so you can safely get rid of that ancestor.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QList, copy problems
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 5th February 2010, 00:06
  2. Return value to QList
    By lyucs in forum Newbie
    Replies: 7
    Last Post: 16th October 2009, 02:31
  3. Regarding the implementation of QList
    By rachit.gupta in forum Qt Tools
    Replies: 1
    Last Post: 23rd September 2009, 12:41
  4. QList inside a QList
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 1st July 2009, 11:59
  5. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.