Results 1 to 3 of 3

Thread: Accessing a class Object by pointer in another class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Accessing a class Object by pointer in another class

    Hi All,

    I recognize that this question falls pretty much into C++, but since I'm using the threaded server example to develop a server, please bare with me...

    As to my question:
    the server class is defined as followed:
    Qt Code:
    1. class Server : public QTcpServer
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. unsigned int nbrClients;
    7. Server ( QObject *parent = 0 );
    8.  
    9. protected:
    10. void incomingConnection ( int socketDescriptor );
    11. };
    To copy to clipboard, switch view to plain text mode 

    in myunit.cpp the constructor:
    myUnit ( int socketDescriptor, QObject *parent );

    in server.cpp I initiate the object like this:
    myUnit *munit = new myUnit ( socketDescriptor,this );

    in myunit.cpp I have a member function that gets fired upon the socket disconnected state by this:
    connect ( &tcpSocket, SIGNAL ( disconnected() ), this, SLOT ( disconnected() ) );

    this is the member function:
    void myUnit::disconnected()
    {
    //server::nbrClients--; provided for clarity of purpose...
    this->quit();
    }

    What I need is to access the nbrClients member inside this function as to decrement it upon socket disconnection...
    I'll appreciate any pointers on how to do so.
    Thanks in advance.
    Pedro Doria Meunier.
    Last edited by jacek; 14th January 2008 at 13:13. Reason: changed [qtclass] to [code]

Similar Threads

  1. Saving object pointer
    By MarkoSan in forum General Programming
    Replies: 4
    Last Post: 11th January 2008, 11:53
  2. Creating object of other class in Run() method
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 15:05

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.