hi
Does Creating a QTcpSocket or QTcpServer on a socket will create a problem(especially in Threading applications)
Thank you.
hi
Does Creating a QTcpSocket or QTcpServer on a socket will create a problem(especially in Threading applications)
Thank you.
Why would it create a problem? Except that it goes out of scope unless you block the execution with an event loop or so.
J-P Nurmi
In the Fortune Client Example QTcpSocket is declared as pointer ,Whereas in the Blocking Fortune Client Example the QTcpSocket is declared without pointer.Does it makes any difference if dont declare QTcpSocket as pointer in the First case.
It's allocated on the heap, because it's created in the constructor and it must remain alive after the constructor. If it was on the stack, the socket object would get automatically destructed after going out of scope, according to normal C++ rules.
Because that example uses waitForXXX() methods to block until certain operations have finished. In that case the object remains alive long enough anyway, so there is no need to allocate it on the heap.Whereas in the Blocking Fortune Client Example the QTcpSocket is declared without pointer.
J-P Nurmi
But it is declared in the private section of the class,So it should be visible to entire class Same as quint16 blockSize variable(please correct me ,i am sure i am missing important concept).It's allocated on the heap, because it's created in the constructor and it must remain alive after the constructor.
If you allocate it on the stack as a member variable and you accidentally happen to pass a parent object, you might get a crash due to double delete; 1) by its parent 2) when going out of scope. Of course you can do it, but you have to be very careful not to break things. Allocating QObjects on the heap with correct parent is less error-prone, I'd say. Furthermore, even if it's not that huge advantage, this also makes a forward declaration sufficient in the header file.
J-P Nurmi
babu198649 (5th December 2008)
Bookmarks