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. Passing QScopedPointer to a member object
Forum Updated to NodeBB v4.3 + New Features

Passing QScopedPointer to a member object

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 669 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by ODБOï
    #1

    Hello,

    Is it possible to pass /share a member QScopedPointer to another member object ?

    example :

    class myClass : public QObject
    {
    public :
    // ctor
     explicit myClass (QObject *parent = nullptr){
      handler = new CommunicationHandler; 
      handler->setClient(&myClient);  // is this possible ? how to implement the "setClient()" method in  CommunicationHandler  pls ?
    }
    private :
     CommunicationHandler *handler;  
     QScopedPointer<QOpcUaClient> myClient;
    }
    

    thank you

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      QScopedPointer has a data() function. Or use a shared pointer or non at all (in this case I don'T see a reason to use one and your example passes an empty pointer so nothing will happen). Passing a pointer to a QScopedPointer is really bad design.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      ODБOïO 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        QScopedPointer has a data() function. Or use a shared pointer or non at all (in this case I don'T see a reason to use one and your example passes an empty pointer so nothing will happen). Passing a pointer to a QScopedPointer is really bad design.

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        @Christian-Ehrlicher hi
        Thank you very much for your answer.

        this works as i expect, but are you saying this is bad design ?

          //CommunicationHandler  class,  needs  a pointer to  QOpcUaClient 
               QOpcUaClient* m_uaClient;           
                void setUaClient(QOpcUaClient *uaClient){
                        m_uaClient = uaClient;    
                }
        
        // base class where  CommunicationHandler   is created
        protected: 
         QScopedPointer<QOpcUaClient> m_client;
            [...]
        {
         handler = new CommunicationHandler; 
         handler->setUaClient(m_client.data());
        }
        
        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @LeLev said in Passing QScopedPointer to a member object:

          but are you saying this is bad design ?

          no, I did not say that this is bad design.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          ODБOïO 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            @LeLev said in Passing QScopedPointer to a member object:

            but are you saying this is bad design ?

            no, I did not say that this is bad design.

            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by
            #5

            @Christian-Ehrlicher
            ok good. Thanks

            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