Results 1 to 6 of 6

Thread: Data structures with qt4

  1. #1
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Data structures with qt4

    Hello
    This is an example of data structures with qt4

    You enter a set of ID
    And then print all the IDs
    Attached Files Attached Files

  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: Data structures with qt4

    What? Data structures in Qt is exactly the same as data structures in C++, unless you use a Qt specific object to hold the data, which you dont.

    Secondly, what you are doing is just reinventing the wheel. There are much better (less code, more readable) ways to do what you have done.

  3. #3
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Data structures with qt4

    Quote Originally Posted by fatjuicymole View Post
    What? Data structures in Qt is exactly the same as data structures in C++, unless you use a Qt specific object to hold the data, which you dont.

    Secondly, what you are doing is just reinventing the wheel. There are much better (less code, more readable) ways to do what you have done.
    Where is this code ?
    The least number of lines and more accurate.

    There is difficulty in building data structures with qt4. If you use inheritance in data structures.

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

    Default Re: Data structures with qt4

    Well, for example:

    "QList<T> is one of Qt's generic container classes. It stores a list of values and provides fast index-based access as well as fast insertions and removals."

    Is far easier to use and more manageable than your example data structure.

  5. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Data structures with qt4

    You can also simply use the STL std::list<T> class, which also has the advantage of being part of the STL's container system. This allows users to swap one container for another without changes to their code, as the API is the same across all classes for the most part.

  6. #6
    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: Data structures with qt4

    Quote Originally Posted by NewLegend View Post
    The least number of lines and more accurate.
    The number of lines of code is not that relevant, consider the two examples:

    Qt Code:
    1. struct one {
    2. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. struct two {
    2. two(const QString &_a, const QString &_b) : m_a(_a), m_b(_b){}
    3. void setA(const QString &a) { m_a = a; }
    4. void setB(const QString &b) { m_b = b; }
    5. const QString &a() const { return m_a; }
    6. const QString &b() const { return m_b; }
    7. private:
    8. QString m_a;
    9. QString m_b;
    10. };
    To copy to clipboard, switch view to plain text mode 

    Which is better? From what point of view? And how about this one?

    Qt Code:
    1. struct three_private : public QSharedData {
    2. three_private() : QSharedData(){}
    3. three_private(const three_private &other) : QSharedData(other), a(other.a), b(other.b){}
    4. };
    5.  
    6. class three {
    7. public:
    8. three() : d(new three_private){}
    9. three(const three &other) : d(other.d){}
    10. void setA(const QString &a) { d->a = a; }
    11. void setB(const QString &b) { d->b = b; }
    12. const QString &a() const { return d->a; }
    13. const QString &b() const { return d->b; }
    14. private:
    15. QSharedDataPointer<three_private> d;
    16. };
    To copy to clipboard, switch view to plain text mode 

    Which is fastest? Which is least error prone? Which is easiest to extend, i.e. by forcing "b" to be lowercase alphanumeric characters only?

    There is difficulty in building data structures with qt4. If you use inheritance in data structures.
    You can use C structures in Qt-based code as well, if you want and you like to inflict pain on yourself while programming

    Edit: Oh, for completeness regarding your code, there is QLinkedList.
    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. structures in QT
    By rk0747 in forum General Programming
    Replies: 8
    Last Post: 5th April 2011, 23:04
  2. Saving hierarchical structures of data.
    By psih128 in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2009, 08:33
  3. How to properly delete structures?
    By aarelovich in forum General Programming
    Replies: 5
    Last Post: 24th February 2009, 00:39
  4. APIs and Data structures
    By crazymoonboy in forum Qt Programming
    Replies: 0
    Last Post: 30th September 2008, 07:56
  5. Replies: 2
    Last Post: 17th April 2006, 21:30

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.