Results 1 to 4 of 4

Thread: How to do a 1:N relationship between classes in Qt?

  1. #1
    Join Date
    Apr 2016
    Posts
    9
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How to do a 1:N relationship between classes in Qt?

    Hello!

    I have two classes that have a 1:N relationship with each other, e.g. and Item class that is connected to an ItemType class. I want to be able to decide with a given Item object and ItemType object if the Item is of that type.

    My idea was to use unique ids for both classes and have a member in Item that stores its ItemType's id. I see Qt has a class named QUuid, but it has no copy constructor. I know I can still hack it, e.g. convert the QUuid to a string, and store that in the Item class, but this idea seems to be going agains the intentions of QUuid.

    What is the correct way to do this in Qt?

    Thank you,
    Viki

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to do a 1:N relationship between classes in Qt?

    Why do you think that QUuid doesn't have a copy constructor?

    Cheers,
    _

  3. #3
    Join Date
    Apr 2016
    Posts
    9
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to do a 1:N relationship between classes in Qt?

    Oops, it has one, sorry.

    I looked at the documentation and it was not listed there: http://doc.qt.io/qt-5/quuid-members.html
    Since QObject does not have one, I assumed it was the case here too, without trying it out.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to do a 1:N relationship between classes in Qt?

    it doesn't have an overloaded one.

    The rule for C++ is, that a class has a copy constructor and assignment operator created by default and a developer can replace them if they choose to.

    Cheers,
    _

Similar Threads

  1. how to clear relationship
    By milos1 in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2015, 05:43
  2. what's the relationship between QOCI and OCI ?
    By silentyears in forum Qt Programming
    Replies: 6
    Last Post: 14th March 2014, 13:29
  3. Replies: 1
    Last Post: 18th April 2012, 16:35
  4. How to get the relationship between two QDockWidget?
    By yunxiaodong in forum Qt Programming
    Replies: 0
    Last Post: 16th August 2011, 08:32
  5. Relationship b/w different classes
    By salmanmanekia in forum Newbie
    Replies: 0
    Last Post: 2nd June 2010, 18:24

Tags for this Thread

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.