Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, January 2007
calling member func - base classTcpSocket and TcpServer


Message 1 in thread

Hello,

Here is a code snippet

class DDDServer : public QTcpServer
{
    Q_OBJECT

public:
    DDDServer(QObject *parent = 0);
    QString getDevicesFromCPD(void);

protected:
    void incomingConnection(int socketDescriptor);

:
}

void DDDServer::incomingConnection(int socketDescriptor)
{

     DDDCliSock *clisock = new DDDCliSock(this);
     :
}

class DDDCliSock : public QTcpSocket
{
    Q_OBJECT
public:
    DDDCliSock(QObject *parent = 0);
private slots:
    void readClient();
:
}

DDDCliSock::DDDCliSock(QObject *parent)
    : QTcpSocket(parent)
{
    connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
     :
}

Now in DDDCliSock::readClient I want to access the QString returned by 
DDDServer::getDevicesFromCPD. How do I do this? This could well be a C++ 
question - but kind of lost with slot being used here.
Also given the intricate relationship between QTcpServer and QTcpSocket - 
your insight into the issue is very valuable.

Any suggestions or pointers will be very helpful.

Thank you

Abhi


--
 [ signature omitted ] 

Message 2 in thread

Sorry - I forgot to mention that getDevicesfromCPD uses a Private member 
data of class DDDServer object
I am unable to use "friend".
Perhaps I am missing something basic here - what options do I have? Even a 
cursory suggestion will be very helpful.

"Abhi Rao" <Abhijit.Rao@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in 
message news:enhn6t$fv8$1@xxxxxxxxxxxxxxxxxxxxx
> Hello,
>
> Here is a code snippet
>
> class DDDServer : public QTcpServer
> {
>    Q_OBJECT
>
> public:
>    DDDServer(QObject *parent = 0);
>    QString getDevicesFromCPD(void);
>
> protected:
>    void incomingConnection(int socketDescriptor);
>
> :
> }
>
> void DDDServer::incomingConnection(int socketDescriptor)
> {
>
>     DDDCliSock *clisock = new DDDCliSock(this);
>     :
> }
>
> class DDDCliSock : public QTcpSocket
> {
>    Q_OBJECT
> public:
>    DDDCliSock(QObject *parent = 0);
> private slots:
>    void readClient();
> :
> }
>
> DDDCliSock::DDDCliSock(QObject *parent)
>    : QTcpSocket(parent)
> {
>    connect(this, SIGNAL(readyRead()), this, SLOT(readClient()));
>     :
> }
>
> Now in DDDCliSock::readClient I want to access the QString returned by 
> DDDServer::getDevicesFromCPD. How do I do this? This could well be a C++ 
> question - but kind of lost with slot being used here.
> Also given the intricate relationship between QTcpServer and QTcpSocket - 
> your insight into the issue is very valuable.
>
> Any suggestions or pointers will be very helpful.
>
> Thank you
>
> Abhi
>
> 


--
 [ signature omitted ] 

Message 3 in thread

On 03.01.07 19:24:09, Abhi Rao wrote:
> Sorry - I forgot to mention that getDevicesfromCPD uses a Private member 
> data of class DDDServer object

Thats no problem, the function is a public function so anybody can
execute it. It doesn't make the slightest difference wether the members
used in the implementation of the function are private or public.

> I am unable to use "friend".

You don't need friend. friend is meant to be used if a class needs
access to the private/protected members of another class because the
public API shouldn't include access to these members.

Andreas

-- 
 [ signature omitted ] 

Message 4 in thread

Thank you - I will work with it  and will post my results

"Andreas Pakulat" <apaku@xxxxxx> wrote in message 
news:20070104045605.GB30374@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> On 03.01.07 19:24:09, Abhi Rao wrote:
>> Sorry - I forgot to mention that getDevicesfromCPD uses a Private member
>> data of class DDDServer object
>
> Thats no problem, the function is a public function so anybody can
> execute it. It doesn't make the slightest difference wether the members
> used in the implementation of the function are private or public.
>
>> I am unable to use "friend".
>
> You don't need friend. friend is meant to be used if a class needs
> access to the private/protected members of another class because the
> public API shouldn't include access to these members.
>
> Andreas
>
> -- 
> You should go home.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/ 


--
 [ signature omitted ] 

Message 5 in thread

On 03.01.07 18:02:04, Abhi Rao wrote:
> class DDDServer : public QTcpServer
> {
>     Q_OBJECT
> 
> public:
>     DDDServer(QObject *parent = 0);
>     QString getDevicesFromCPD(void);
> 
> protected:
>     void incomingConnection(int socketDescriptor);
> 
> :
> }
> 
> void DDDServer::incomingConnection(int socketDescriptor)
> {
> 
>      DDDCliSock *clisock = new DDDCliSock(this);
>      :
> }
> 
> class DDDCliSock : public QTcpSocket
> {
>     Q_OBJECT
> public:
>     DDDCliSock(QObject *parent = 0);
> private slots:
>     void readClient();
> :
> }
> 
> Now in DDDCliSock::readClient I want to access the QString returned by 
> DDDServer::getDevicesFromCPD. How do I do this?

By having a pointer to the DDServer instance stored in the DDCliSock
class or by having only 1 DDServer at all (i.e. a singleton) and
providing a instance() method that returns a pointer to the DDServer.

As you already pass DDServer as parent, you could just change the
constructor for DDDCliSock to take the DDDServer pointer (instead of
QObject) and store the pointer in a member variable.

> This could well be a C++ 
> question - but kind of lost with slot being used here.

A slot is nothing else than a function. The only difference is that it
might be called from code that you don't control (i.e. signal).

Andreas

-- 
 [ signature omitted ]