
Originally Posted by
fullmetalcoder
Nop... If that's really the code you're using (not talking about completeness here just exactitude...) Then the connection must close as soon as the execution leaves the scope where your socket is instantiated (loop, function, whatever) because you don't use dynamic allocation but heap allocation... Thus the socket object is destroyed and stops communicating with your server... I think you should read some more about OOP and C++...
When I call the function like this : (session is a pointer to class object)
session->tcpSocket.write((const char*)buf,len);
session->tcpSocket.waitForBytesWritten();
session->tcpSocket.write((const char*)buf,len);
session->tcpSocket.waitForBytesWritten();
To copy to clipboard, switch view to plain text mode
I get this error :
Unhandled exception at 0x670afb8a (QtCored4.dll) in MyProgram.exe: 0xC0000005: Access violation reading location 0xcdcdcdd9.
and it's break at this location :
private:
private:
-> Q_DECLARE_PRIVATE(QIODevice)
Q_DISABLE_COPY(QIODevice)
To copy to clipboard, switch view to plain text mode
I access the tcpSocket object that was created in a running thread.
If I want to maintain the connection what should I do ?
create a static object ?
By the way isn't heap allocation & dynamic allocation is the same thing, just with different terms ?
I read this on a book, chapter 20.3 of "An Introduction to Design Patterns in C++ with Qt" :
The heap or free storage (dynamic storage): Objects created via new are examples.
The lifetime of a heap object is determined entirely by the use of new and delete.
In general, the allocation and freeing of heap objects should be in carefully encapsulated classes.
And I read this on a book, chapter 3 of "Memory Management, Algorithms and Implementations in C-C++" :
Heap memory allocation, also known as dynamic memory allocation
(DMA), consists of requesting memory while an application is running
from a repository known as the heap.
Bookmarks