⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

QSharedDataPointer and QSharedData compile problem

  • Hi all, i have some problem with compiling such code

    // This is main shared library of my app
    in *.h file :

    @class GroupData; // which is in groupdata.h and included in group.cpp
    class Group
    Group( const Group &other );
    QSharedDataPointer<GroupData> d;
    // GroupData in separate groupdata.h
    class GroupData
    GroupData( const GroupData &other ):QSharedData(other),

    QString title;

    // this compile, without problems

    Problem starts when i include main lib in another shared library, gcc says that the: forward declaration of 'struct GroupData'

    Myabe i am something missed ?

  • In other library i error in next line :

    @QList<Group> groups;

  • from my experience, you shouldn't use forward declarations in combination with shared pointers, smart pointers, etc.
    When compiling the template, problems can arise when it comes to resolving the destructor the pointer should call (the compiler doesn't know the destructor due to the forward declaration).

    I'm guessing this is GCC's way of telling you not to do this...

  • Yes, it claims also about destructor will not be called. But when how to hide privat shared data. And Qt docs says that putting private shared data in seperate class is common use.

Log in to reply