View Poll Results: Do you use Boost libraries?

Voters
20. You may not vote on this poll
  • Yes, I use Boost libraries for Qt applications.

    3 15.00%
  • Yes, I do, but only for non-Qt applications.

    3 15.00%
  • No, I don't use them at all.

    14 70.00%
Results 1 to 20 of 27

Thread: Boost libraries

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Boost libraries

    Smart pointers delete objects? I think we're having a different concept of smart pointers... Mine is that it sets the pointer to 0 once the object pointed is deleted. The concept you described I'd call a hijacking pointer and I don't want my pointers hijacked Anyway: QPointer.

  2. #2
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Boost libraries

    Hi,

    Not heard of 'hijacking' pointer

    I'll take a look at QPointer, thanks!

    Regards,
    Steve

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

    Default Re: Boost libraries

    It's hijacking, because when it's destroyed, it destroys the pointed object as well (that's what you said). This means that if it doesn't have ownership of the object, it'll hijack it from the real owner. And it's probably implemented more or less like so:
    Qt Code:
    1. template <typename T> class HijackingPointer {
    2. public:
    3. HijackingPointer(T *ptr=0), m_ptr(ptr){}
    4. void setPointer(T* ptr){ m_ptr = ptr; }
    5. ~HijackingPointer(){ delete m_ptr; }
    6. // + operator T*, operator * and operator ->
    7. private:
    8. T* m_ptr;
    9. };
    To copy to clipboard, switch view to plain text mode 

    I don't think I have to link to a bloated library just for this small snippet.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Boost libraries

    Quote Originally Posted by wysota View Post
    I don't think I have to link to a bloated library just for this small snippet.
    std::auto_ptr from STL is the one that "hijacks" pointers, not the classes from Boost's Smart Pointers family.

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

    Default Re: Boost libraries

    So Boost pointers won't do that for you:
    . I have 'played' with it in the past and used mainly the smart pointers as I often forget to delete pointers and using these, it does it for you.
    Right?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Boost libraries

    Quote Originally Posted by wysota View Post
    So Boost pointers won't do that for you: [...] Right?
    It depends which one you choose.

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

    Default Re: Boost libraries

    So is there a pointer in the family that deletes objects pointed to when it's deleted but doesn't hijack the object (for me this is contradictory, but maybe I just can't imagine the situation)?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Boost libraries

    Quote Originally Posted by wysota View Post
    So is there a pointer in the family that deletes objects pointed to when it's deleted but doesn't hijack the object (for me this is contradictory, but maybe I just can't imagine the situation)?
    Boost has three kinds of smart pointers:
    • shared pointers, which share the ownership amongs them,
    • scoped pointers, which take the ownership for themselves,
    • weak pointers, which don't take the ownership, but know when the object was destroyed.

    All these three kinds of smart pointers are well behaved and the term "hijacking" isn't appropriate. It's just as if you said that QCoreApplication::postEvent() "hijacks" pointers, because it takes their ownership --- it doesn't, it's just a part of its contract.

    If you want to call something "pointer hijacking", take a look what std::auto_ptrs do on copy --- they're like hungry hienas, which steal a dead antilope from each other.

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

    Default Re: Boost libraries

    So "weak pointer" is an equivalent of QPointer, "scoped pointer" does to pointers more or less what QMutexLocker does to mutexes and shared pointer is a combination of the two that does reference counting. Correct? Of course all these might fail if you use any regular pointers with the same object.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Boost libraries

    Quote Originally Posted by wysota View Post
    Correct?
    Yes.

    Quote Originally Posted by wysota View Post
    Of course all these might fail if you use any regular pointers with the same object.
    Like everything which deals with pointers.

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

    Default Re: Boost libraries

    Quote Originally Posted by jacek View Post
    Like everything which deals with pointers.
    But not QPointer

  12. #12
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Boost libraries

    Quote Originally Posted by wysota View Post
    But not QPointer
    It's nothing to boast about if your smart pointer is restricted to QObject descendants.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

Similar Threads

  1. Combining Qt with other libraries (Boost, ...)
    By Raistlin in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2007, 06:28
  2. how to add new libraries to QT
    By whoops.slo in forum Newbie
    Replies: 3
    Last Post: 12th January 2007, 11:15
  3. Qt 3.3 libraries
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st December 2006, 17:25
  4. Standardization on libraries
    By brcain in forum General Discussion
    Replies: 13
    Last Post: 16th August 2006, 22:56
  5. Replies: 4
    Last Post: 7th March 2006, 08:52

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.