hello everybody<br>i am using QGIS 0.7.9<br>Aim of my plugin: To display points received from various algorithms simultaneously on canvas.<br><br>Situation is like on top of map i am displaying location of points received from a client-socket using TCP/IP. It works fine till only one such socket is opened and read from .Updation and movement of points goes well. But as soon as i start reading from multiple client/sockets and try to display data , all situation goes awery. Then only data from recently activated socket/client is updated and displayed. This is where i am looking for help.
<br><br>How i have implemented: For storing data from various socket i am using QHash with key as socket Descriptor id and Value as in a QList.<br>For each readyRead() received signal i gets i add in hash with correspondent socket descriptor as key.
<br>here is part of code i am putting:<br><br>// this slot will be called for newConnection() signal<br>void tcpCock::activatingNewConnection()<br>{<br> tcpSocket=tcpServer->nextPendingConnection();<br> connect( tcpSocket, SIGNAL(disconnected()),tcpSocket, SLOT(deleteLater()));
<br> connect( tcpSocket,SIGNAL(readyRead()),this,SLOT(updatePixmap()));<br> //provide a connect for linking socket exiting status to one of slo which disconnects drawShape() from refresh signal.<br> connect( tcpSocket,SIGNAL(disconnected()),this,SLOT(socketDisconnected()));
<br> pIntQlist= new QList<int> ;<br> hash.insert(tcpSocket->socketDescriptor(),pIntQlist);<br>}<br><br><br>//drawshape() function defination for QgsMapCanvasItem's pure virtual one<br>void tcpCock::drawShape(QPainter & p)
<br>{<br> //load the pixamap to be displayed<br> QString myFileNameQString= "/home1/qgis/images/cock/cock.png";<br> QPixmap myQPixmap;<br> myQPixmap.load(myFileNameQString);<br> <br><br> QHashIterator<int, QList<int>* > itr(hash);
<br> while ( itr.hasNext())<br> { itr.next() ;//possible outcome of error<br> //tempList=itr.value();<br> <br> QListIterator<int> tempListItr(*itr.value());<br> tempListItr.toBack
();<br> y=tempListItr.previous();<br> x=tempListItr.previous();<br> QgsPoint qpt(x,y);<br> QPoint pt=toCanvasCoords(qpt);<br> move(pt.x(),pt.y());// added to check for movement of all elements-questionable
<br> p.drawPixmap(pt.x(),pt.y(),myQPixmap);<br> }<br>}<br><br><br>//This slot will be called for every readyRead()signal<br>void tcpCock::updatePixmap()<br>{<br> <br> QTcpSocket *tempSock=dynamic_cast<QTcpSocket *>(sender());
<br> if(tempSock)<br> {<br> QHash<int, QList<int>* >::const_iterator itr=hash.find(tempSock->socketDescriptor());<br> <br> QString st;<br> QDataStream in(tcpSocket);<br> in.setVersion(QDataStream::Qt_4_0);
<br> if( tempSock->bytesAvailable() <= 0 )// changed from tcpSocket since tcpsocket will look for newely activeted connection only<br> {<br> //cout<<"\nNothing Available for reading";
<br> return;<br> }<br> in >>st;<br> int i=0;<br> QChar *data = st.data();<br> while (*data!=' ')<br> {<br> ++data;<br> i++;<br> }<br> QString s1=st.left(i);<br> x=s1.toInt
();<br> QString s2=st.mid(i+1);<br> y=s2.toInt();<br> itr.value()->append(x);<br> itr.value()->append(y);<br> <br> move(x,y);<br> QgsRect r=mQGisApp->getMapCanvas()->fullExtent();<br> setRect(r);
<br> show();<br> updateCanvas();<br> }<br>}<br><br>What i feel is not ok with this piece of code is i am not able to address to canvas item corresponding to data received from each client. To avoid it i am drawing each canvas item again at their last available location in
hash.value() ie list. But output is that only newely created socket -canvs item is updated.<br>While using gdb i observed with 3 client connections. Every canvas item starts again from location provided by newly activated client. and after that all follow the path.
<br>kindly help me in this matter.<br><br>regards<br>quick nitin<br><br>