PDA

View Full Version : assign problem with array of QTcpSocket



radeberger
29th April 2010, 10:18
Hi everyboby!

I have QTcpSocket, QTcpServer arrays, declared as follow:

QTcpServer *tcpClient;
QTcpSocket *tcpServer;

in the constructor:

tcpServer = new QTcpServer[numConnec];
tcpClient = new QTcpSocket[numConnec];

I connected the signal "newConnection" of the first QTcpServer with my slot acceptconnection as follow:

connect(&tcpServer[0], SIGNAL(newConnection()),SLOT(acceptConnection()), Qt::DirectConnection);

and in the acceptconnection I have:

&tcpClient[0] = &tcpServer[0].nextPendingConnection();
connect(&tcpClient[0], SIGNAL(readyRead()),SLOT(startRead0()), Qt::DirectConnection);

I get the following error: '&' requires l-value in the &tcpClient[0] = &tcpServer[0].nextPendingConnection();

do you know how I'm doing bad?

Thanks in advance!

wysota
29th April 2010, 10:25
&tcpClient[0] = &tcpServer[0].nextPendingConnection();
This is not a valid (or at least not a useful) C++ statement.

You probably wanted:

tcpClient[0] = tcpServer[0]->nextPendingConnection();

And consider using QVector or std::vector instead of those C arrays.

radeberger
29th April 2010, 11:16
well, if a use

tcpClient[0] = tcpServer[0]->nextPendingConnection();

I get this error:

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'QTcpSocket *' (or there is no acceptable conversion)

tbscope
29th April 2010, 13:00
You are not assigning a QTcpSocket* to a QTcpSocket*.

Create a list or vector of QTcpSocket* like Wysota said.
Example QList<QTcpSocket *> mySocketList;

Add new sockets to that list and use the QList functions to access them.

radeberger
29th April 2010, 15:20
ok, thank you very much, I will try it with a list...

radeberger
1st May 2010, 16:47
Hi!

I tried this with the sender() function but I had some trouble.

in the slot function I have:

myclass *tcpServerSender = qobject_cast<myclass*>(QObject::sender());

but this pointer is always NULL, do you have any ideas, how can I get the pointer to the object?

thanks!

squidge
1st May 2010, 17:03
You shouldn't really be using sender() and that ugly type casting. Use QSignalMapper instead.