Results 1 to 3 of 3

Thread: Sharing vectors between classes

  1. #1
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Sharing vectors between classes

    I have a pointcloud class that stores points:

    Qt Code:
    1. class pointCloud : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit pointCloud(QObject *parent = 0);
    6.  
    7. signals:
    8.  
    9. public slots:
    10.  
    11. void addPoint(float x, float y, float z);
    12.  
    13. private:
    14.  
    15. struct point {
    16.  
    17. float x;
    18. float y;
    19. float z;
    20.  
    21. };
    22.  
    23.  
    24. std::vector<point> points;
    25. };
    To copy to clipboard, switch view to plain text mode 



    i create point cloud:

    pointCloud pointcloud;

    and filled the vector with points.

    I now want to pass this vector to a QGLWidget for display.

    Whats the best way to share this data?

    Thanks,

    Dubstar_04

  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: Sharing vectors between classes

    Any way that makes sense for your application and is valid C++ is good. There is not single "best" answer to a broad general question.

  3. #3
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Sharing vectors between classes

    I have tried passing the pointcloud object as a pointer and a reference and i couldn't get either to work.

    would it be best to pass just the points vector?

    The QGLWidget shouldn't alter the points data, just display it. i have read that a const vector by reference should be used, but i am a little out of my depth here.

    Thanks for any tips,

    Dubstar_04

Similar Threads

  1. Replies: 3
    Last Post: 5th July 2013, 15:09
  2. Replies: 7
    Last Post: 12th July 2011, 15:50
  3. Replies: 1
    Last Post: 9th April 2011, 22:07
  4. Classes with Implicit Sharing
    By weaver4 in forum Newbie
    Replies: 5
    Last Post: 15th January 2011, 19:57
  5. How to correctly subclass classes that use implicit sharing
    By Gh0str1d3r in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2010, 10:42

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.