Results 1 to 3 of 3

Thread: Hidden problem with dynamic created pointer?

  1. #1
    Join Date
    Jun 2011
    Posts
    12
    Thanks
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Question Hidden problem with dynamic created pointer?

    Is there any hidden problem with this code, please? I'w worried about living time of dynamic created "*connection" pointer.
    Qt Code:
    1. void TMyTCPSrv::incomingConnection(int sockDesc)
    2. {
    3. TConnection *connection = new TConnection(this);
    4. connection->setSocketDescriptor(sockDesc);
    5.  
    6. // Send read message to this
    7. connect(connection, SIGNAL(toLocalServer(const QString&)),
    8. this, SLOT(onReadFromClient(const QString&)), Qt::QueuedConnection);
    9. }
    10.  
    11. class TConnection: public QTcpSocket
    12. {
    13. ...
    14. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hidden problem with dynamic created pointer?

    TConnection will live for as long as TMyTCPSrv lives (no shorter, no longer), presuming that you passing 'this' to the ctor is a parent argument.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jun 2011
    Posts
    12
    Thanks
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Hidden problem with dynamic created pointer?

    Ok. Thank you

Similar Threads

  1. QFileInfo::created() Problem Under POSIX!!
    By Mans in forum Qt Programming
    Replies: 3
    Last Post: 16th May 2011, 02:34
  2. Replies: 1
    Last Post: 4th December 2010, 17:20
  3. Replies: 9
    Last Post: 6th August 2010, 22:13
  4. Dynamic pointer type
    By estanisgeyer in forum General Programming
    Replies: 3
    Last Post: 9th October 2008, 16:51
  5. Replies: 27
    Last Post: 16th May 2008, 07:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.