Results 1 to 4 of 4

Thread: Strange behavior of Q_DECLARE_PRIVATE_D() macro

  1. #1
    Join Date
    Nov 2015
    Posts
    41
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Strange behavior of Q_DECLARE_PRIVATE_D() macro

    Hi, I found strange behavior of Q_DECLARE_PRIVATE_D macro

    For example when i declare:
    Qt Code:
    1. QScopedPointer<MetaDataPrivate> d_ptr;
    2. Q_DECLARE_PRIVATE(MetaData)
    To copy to clipboard, switch view to plain text mode 

    then it works fine but when I try use Q_DECLARE_PRIVATE_D macro with second parameter for name of my pointer
    Qt Code:
    1. QScopedPointer<MetaDataPrivate> d;
    2. Q_DECLARE_PRIVATE_D(d, MetaData)
    To copy to clipboard, switch view to plain text mode 

    I get error:
    error: invalid cast from type 'QScopedPointer<MetaDataPrivate>' to type 'MetaDataPrivate*'
    Maybe someone know what I am doing wrong here? How I can use Q_DECLARE_PRIVATE_D with my name of pointer.

    Regards,

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Strange behavior of Q_DECLARE_PRIVATE_D() macro

    maybe
    Qt Code:
    1. QScopedPointer<MetaDataPrivate> d;
    2. Q_DECLARE_PRIVATE_D(d.data(), MetaData)
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Nov 2015
    Posts
    41
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Strange behavior of Q_DECLARE_PRIVATE_D() macro

    These macros are different:

    Qt Code:
    1. #define Q_DECLARE_PRIVATE(Class) \
    2. inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \
    3. inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \
    4. friend class Class##Private;
    5.  
    6. #define Q_DECLARE_PRIVATE_D(Dptr, Class) \
    7. inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(Dptr); } \
    8. inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(Dptr); } \
    9. friend class Class##Private;
    To copy to clipboard, switch view to plain text mode 

    diferrent part

    Q_DECLARE_PRIVATE
    Qt Code:
    1. (qGetPtrHelper(d_ptr));
    To copy to clipboard, switch view to plain text mode 
    Q_DECLARE_PRIVATE_D
    Qt Code:
    1. (Dptr);
    To copy to clipboard, switch view to plain text mode 

    but I really do not know why... Maybe it is bug in Qt?
    I think that Q_DECLARE_PRIVATE_D macro should work with QScopedPointer similar as Q_DECLARE_PRIVATE macro.


    Added after 13 minutes:


    anda_skoa yes, it works but i wonder why they changed Q_DECLARE_PRIVATE_D macro and we can not pass QScopedPointer directly like in Q_DECLARE_PRIVATE.
    Last edited by Scope; 22nd February 2016 at 16:33.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Strange behavior of Q_DECLARE_PRIVATE_D() macro

    The missing piece is likely that qGetPtrHelper() function, it must have overloads for raw pointer, scoped pointer and maybe others.

    You could test that theory, i.e. use qGetPtrHelper(Dptr) inside the cast parentheses and submit a patch on Qt's gerrit if it works.

    Cheers,
    _

Similar Threads

  1. strange behavior of qt 5.4
    By gisac in forum Qt Programming
    Replies: 4
    Last Post: 26th December 2015, 21:32
  2. QLCDNumber strange behavior!
    By saman_artorious in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2013, 13:08
  3. setCellWidget - strange behavior
    By Archa4 in forum Newbie
    Replies: 5
    Last Post: 28th April 2011, 08:26
  4. QAudioInput example strange behavior
    By m15ch4 in forum Qt Programming
    Replies: 0
    Last Post: 13th August 2010, 06:55
  5. Strange behavior of QSyntaxHighlighter in Qt3
    By lorebett in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2009, 14:50

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.