Results 1 to 6 of 6

Thread: what is equivalent of an array in QT

  1. #1
    Join Date
    Feb 2013
    Posts
    50
    Thanks
    5

    Default what is equivalent of an array in QT

    Hi, in iOS there is NSMutableArray which is a dynamic array of any type of objects.
    I think the best equivalent in Qt would be QVariantList right?? Thanks.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: what is equivalent of an array in QT

    Or QVector<QVariant> if the list is fixed or relatively static in length.

  3. #3
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what is equivalent of an array in QT

    In Qt and in C++ there's no NSObject. So there is no direct alternative.
    What you should use is then depends on what you want to do.
    If you want to store value-types and pass them to scripts, you should use QVariantList.
    If you want to to store widgets, you should use one of the Qt template container and store pointers, for example QList<QWidget*>.
    More general case for non-gui elements is container with QObject*.

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

    Default Re: what is equivalent of an array in QT

    Technically speaking QVariant can also hold a pointer to QObject (or QWidget).
    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.


  5. #5
    Join Date
    Feb 2013
    Posts
    50
    Thanks
    5

    Default Re: what is equivalent of an array in QT

    Quote Originally Posted by ChrisW67 View Post
    Or QVector<QVariant> if the list is fixed or relatively static in length.
    there maybe cases when the array is not fixed in length...

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

    Default Re: what is equivalent of an array in QT

    Quote Originally Posted by ggdev001 View Post
    there maybe cases when the array is not fixed in length...
    What matters is if you often insert into the middle of the array or not. Appending at the end is relatively cheap with QVector. If you want to frequently insert in the middle, it is better to use QList.
    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. Cast QString array to std::string array
    By Ishtar in forum Newbie
    Replies: 4
    Last Post: 15th July 2011, 08:28
  2. cin Equivalent in Qt
    By amiref in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2011, 18:16
  3. Replies: 2
    Last Post: 12th November 2010, 14:42
  4. declare an array of QSemaphore and array of slot functions
    By radeberger in forum Qt Programming
    Replies: 11
    Last Post: 2nd May 2010, 13:24
  5. equivalent
    By deepa.selvaraj in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 18:33

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
  •  
Qt is a trademark of The Qt Company.