Results 1 to 3 of 3

Thread: Using std::shared_ptr for Qt objects

  1. #1
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Using std::shared_ptr for Qt objects

    Hello!

    Please, help me to solve this problem:

    DownLoader.h:19: error: no matching function for call to 'Downloader::connect(std::shared_ptr<QNetworkReply >&, const char*, Downloader* const, const char*)'
    * * * * * * * * *this, SLOT(replyFinished( ) ) );
    Qt Code:
    1. #ifndef DOWNLOADER_H
    2. #define DOWNLOADER_H
    3.  
    4. #include <memory>
    5.  
    6. #include <QObject>
    7. #include <QString>
    8. #include <QNetworkReply>
    9. #include <QNetworkRequest>
    10. #include <QNetWorkAccessManager>
    11.  
    12. class Downloader : public QObject
    13. {
    14. * *Q_OBJECT
    15.  
    16. * *Downloader( )
    17. * *{
    18. * * * *connect( m_reply, SIGNAL( finished( ) ),
    19. * * * * * * * * this, SLOT( replyFinished( ) ) );
    20. * *}
    21.  
    22. * *void fetch( const QString &url )
    23. * *{
    24. * * * *m_reply.reset(m_manager->get( QNetworkRequest( QUrl( url ) ) ) );
    25. * *}
    26.  
    27. signals:
    28. * *void signalWithContent( QString * );
    29.  
    30. private slots:
    31. * *void replyFinished( )
    32. * *{
    33. * * * *QByteArray data = m_reply->readAll( );
    34. * * * *QString content( data );
    35. * * * *emit signalWithContent( &content );
    36. * *}
    37.  
    38. private:
    39. * *std::shared_ptr<QNetworkAccessManager> m_manager =
    40. * * * * * *std::make_shared<QNetworkAccessManager>( new QNetworkAccessManager( this ) );
    41.  
    42. * *std::shared_ptr<QNetworkReply> m_reply;
    43. };
    44.  
    45. #endif // DOWNLOADER_H
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2011
    Posts
    27
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using std::shared_ptr for Qt objects

    Qt Code:
    1. QObject::connect(m_reply.get(),SIGNAL(finished()),this,SLOT(replyFinished());
    To copy to clipboard, switch view to plain text mode 
    (m_reply is NOT a QObject)

  3. The following user says thank you to thomas@itest for this useful post:

    8Observer8 (18th June 2014)

  4. #3
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: Using std::shared_ptr for Qt objects


Similar Threads

  1. 3d objects in QT
    By waman.prabhu in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2011, 10:11
  2. Storing boost.shared_ptr in a QVariant
    By negritot in forum Qt Programming
    Replies: 3
    Last Post: 4th October 2010, 22:42
  3. QSharedPointer vs Boost::tr1::shared_ptr()
    By photo_tom in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2010, 16:48
  4. Replies: 3
    Last Post: 9th January 2010, 15:47
  5. Replies: 7
    Last Post: 18th July 2006, 21:33

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.