Results 1 to 7 of 7

Thread: how to get the info if a qvector element has been set?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how to get the info if a qvector element has been set?

    A simple example of what i mean, plain old C style nothing much of C++,
    Qt Code:
    1. double v[10];
    2. QVector<double*> pv(10);
    3.  
    4. for(int i = 0; i < pv.size(); i++)
    5. {
    6. if((i == 5) or (i == 6)) //no 6th and 7th elements
    7. pv = 0;
    8. else
    9. pv = &v[i];
    10. }
    11.  
    12. for(i = 0; i < pv.size(); i++)
    13. {
    14. if(pv[i])
    15. std::cout << *(pv.at(i)) ; //01234789
    16. }
    To copy to clipboard, switch view to plain text mode 
    This is very basic example. I am not very clear of you actual requirement behind this, but I understand you need a container which is capable to indicate not used elements. Unlike other programing languages (mostly scripting based), which have something line "nothing" / "not initialized" for not set variables, C / C++ does not have anything like this. One alternate way is to use default ctor to set a "not initialized" value (which in many cases is still a valid value, 0 in your case).

    I see you might end-up having your own element class (not container class), or doing something like this example, or as already suggested using some other default value (-99999, NAN) other than 0.
    Last edited by Santosh Reddy; 15th June 2011 at 08:30. Reason: updated contents

Similar Threads

  1. [QML] Video element
    By grezly in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2011, 17:26
  2. casting qvector element
    By rivci in forum Newbie
    Replies: 1
    Last Post: 4th April 2011, 13:58
  3. Remove element of xml
    By VitaliBR in forum Newbie
    Replies: 17
    Last Post: 16th February 2011, 13:28
  4. Help with QML Pathview element
    By chetu1984 in forum Newbie
    Replies: 0
    Last Post: 7th February 2011, 04:49
  5. Can I translate data with GUI element.
    By mourad in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2008, 09:41

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.