Results 1 to 2 of 2

Thread: Right storage QGenericMatrix in QList or QQLinkedList or in an best container?

  1. #1
    Join Date
    Mar 2018
    Qt products

    Default Right storage QGenericMatrix in QList or QQLinkedList or in an best container?

    I have to store data in a several QGenericMatrix<4,4,float> (or in a matrixNxN dimension) like this:
    QList< QGenericMatrix<4,4,float> > list_matrix_trasf;
    QGenericMatrix<4,4,float> empty_matrix;

    for (int i=0; i<4; i++){
    for (int j=0; j<4; j++){
    empty_matrix(i,j) = 0.0;

    int num_storage = 10;

    for (int i=0; i<num_storage; i++){

    .. charge the right data in matrix .. doing calculus like this ..

    QGenericMatrix<4,4,float> goal_matrix;
    QGenericMatrix<1,4,float> goal_vector;
    QGenericMatrix<1,4,float> test;
    test(0,0) = 1.0; // Coord. X
    test(1,0) = 0.0; // Coord. Y
    test(2,0) = 0.0; // Coord. Z
    test(3,0) = 1.0; // never mind

    goal_matrix = list_matrix_trasf[1]*list_matrix_trasf[0];
    .. or ..
    goal_matrix = list_matrix_trasf[3]-list_matrix_trasf[2];
    .. and so on ..

    goal_vector = goal_matrix * test_vector

    I need to access to the data in writing and read mode quickly and more often (read data from file and storage it in a matrix_4x4 or in a matrix_NxN dimension), to do matrix calculus in different way, view result data if request in a 3D space.

    my question is Qlist is the right contenitor do the job, or an other container classes is better,or i have to do it in a different way?

  2. #2
    Join Date
    Jul 2008
    Thanked 58 Times in 56 Posts
    Qt products
    Qt4 Qt5
    Unix/X11 Windows

    Default Re: Right storage QGenericMatrix in QList or QQLinkedList or in an best container?

    Hi, the Qt docs state the following:
    QVector should be your default first choice. QVector<T> will usually give better performance than QList<T>, because QVector<T> always stores its items sequentially in memory, where QList<T> will allocate its items on the heap unless sizeof(T) <= sizeof(void*) and T has been declared to be either a Q_MOVABLE_TYPE or a Q_PRIMITIVE_TYPE using Q_DECLARE_TYPEINFO. See the Pros and Cons of Using QList for an explanation.
    However, QList is used throughout the Qt APIs for passing parameters and for returning values. Use QList to interface with those APIs.
    If you need a real linked list, which guarantees constant time insertions mid-list and uses iterators to items rather than indexes, use QLinkedList.
    Quoted from


    edit: additionally I don't think that the container will have an impact that is large enough to see if you do complex matrix calculations.

  3. The following user says thank you to Ginsengelf for this useful post:

    andreaQt (30th July 2020)

Similar Threads

  1. QGenericMatrix with custom Template Type
    By Qtonimo in forum Qt Programming
    Replies: 24
    Last Post: 9th August 2012, 13:28
  2. help -- removing items from QList container
    By drinkwater in forum Newbie
    Replies: 4
    Last Post: 28th January 2012, 16:03
  3. Replies: 1
    Last Post: 28th August 2011, 06:36
  4. Quick ? about qSort(Container & container)
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2007, 11:20


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.