Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSharedDataPointer and QSharedData compile problem
Forum Updated to NodeBB v4.3 + New Features

QSharedDataPointer and QSharedData compile problem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxvanceffer
    wrote on last edited by
    #1

    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
    {
    public:
    Group();
    Group( const Group &other );
    ...
    private:
    QSharedDataPointer<GroupData> d;
    };
    @
    @
    //------------------------------------------------------------------------
    // GroupData in separate groupdata.h
    class GroupData
    {
    public:
    GroupData(){}
    GroupData( const GroupData &other ):QSharedData(other),
    title(other.title){}

    ~GroupData(){...}
    ...
    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 ?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxvanceffer
      wrote on last edited by
      #2

      In other library i error in next line :

      @QList<Group> groups;
      groups.push_back(group);@

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rschaub
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxvanceffer
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved