Results 1 to 5 of 5

Thread: combine QLisdt and a simple structure

  1. #1
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default combine QLisdt and a simple structure

    Most posts on this subject go way beyond what I want, and I quickly loose track.

    I have a structure
    Qt Code:
    1. typedef structure LDD_POINT{
    2. int row;
    3. int col;
    4. }LDD_POINT;
    To copy to clipboard, switch view to plain text mode 

    in my class I define:

    Qt Code:
    1. QList <LDD_POINT> *lddlist;
    To copy to clipboard, switch view to plain text mode 

    then with each new point in the code:

    Qt Code:
    1. ldd_point *p = new LDD_POINT;
    2. lddlist->append(p);
    To copy to clipboard, switch view to plain text mode 

    which doesn't work:
    c:\Qt\2010.05\qt\include\QtCore\..\..\src\corelib\ tools\qlist.h:493: candidates are: void QList<T>::append(const T&) [with T = LDD_POINT]
    c:\Qt\2010.05\qt\include\QtCore\..\..\src\corelib\ tools\qlist.h:819: void QList<T>::append(const QList<T>&) [with T = LDD_POINT]

    So obviously I am doing something too simple. I don't understand the const T stuff, what is the correct format, or point me to an example...

    Thanks
    Last edited by wysota; 25th January 2011 at 00:47. Reason: missing [code] tags

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: combine QLisdt and a simple structure

    That is because your list contains objects (you declare it: QList <LDD_POINT>) and you are trying to add pointers to LDDD_POINT (append(p) )

    One solution is to use QList<YourStruct*>

    And don't forget to iterate over the QList and delete all the pointers, that should be done after you are done working with that pointers and before the QList gets out of scope.

  3. #3
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: combine QLisdt and a simple structure

    thanks, I also found in an example
    QList <LDD_POINT const *> listldd;
    but I do know the effect of adding the const in this case

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: combine QLisdt and a simple structure

    Short answer is that QList<TYPE const*> will contain pointers to constant TYPE objects... so that you can't modify the objects using the pointer in the QList. (but you can modify pointers to "point" elsewhere)


    A longer answer can be found here (i really recommend you read it)

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

    Default Re: combine QLisdt and a simple structure

    And I suggest you don't use pointers.
    Qt Code:
    1. QList<LDD_POINT> lddlist; // no pointers
    2. lddlist.append(LDD_POINT()); // no pointers, no "new" operator
    To copy to clipboard, switch view to plain text mode 
    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. Replies: 4
    Last Post: 5th September 2010, 10:08
  2. Qt Assistant how to combine QtAssistant with Eclipse?
    By silence in forum Qt Tools
    Replies: 1
    Last Post: 14th April 2010, 12:25
  3. Howto combine a slider and a progress bar?
    By Cruz in forum Qt Programming
    Replies: 3
    Last Post: 21st March 2010, 12:09
  4. how to combine keypress event and mousebuttonpress event?
    By hildebrand in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2009, 23:08
  5. Combine C++ Qt with PyQT
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 7th January 2009, 16:14

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.