Take the QtOrNot quiz,
and see if you can tell
Qt code from Symbian C++
Task: Download a web page
_LIT8( KUserAgent, "Example" );
_LIT8( KAccept, "*/*" );

class MMyDownloaderObserver
{
public:
    virtual void ClientHeaderReceived(
        const TDesC& aHeaderData ) = 0;
    virtual void ClientBodyReceived(
        const TDesC8& aBodyData ) = 0;
};

class CMyDownloader : public CBase,
        public MHTTPTransactionCallback
{
public:
    static CMyDownloader* NewLC(
        MMyDownloaderObserver& aObserver);
    ~CMyDownloader();
    void StartDownloadL(const TDesC8& aUri);
    void CancelTransactionL();

private:
    void ConstructL();
    CMyDownloader(MMyDownloaderObserver& iObserver);
    void SetHeaderL(RHTTPHeaders aHeaders,
                     TInt aHdrField,
                     const TDesC8& aHdrValue);
    void HandleRunErrorL(TInt aError);
private:
    void MHFRunL( RHTTPTransaction aTransaction,
        const THTTPEvent& aEvent );
    TInt MHFRunError( TInt aError,
                      RHTTPTransaction aTransaction,
                      const THTTPEvent& aEvent );
private:
    RSocketServ             iSocketServ;
    RConnection             iConnection;
    RHTTPSession            iSession;
    RHTTPTransaction        iTransaction;
    MMyDownloaderObserver&  iObserver;
};

CMyDownloader* CMyDownloader::NewLC(
    MWebClientObserver& aObserver)
{
    CMyDownloader* self = new (ELeave)
        CMyDownloader( aObserver );
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
}

CMyDownloader::CMyDownloader(
    MWebClientObserver& aObserver)
    : iObserver( aObserver ) { }

CMyDownloader::~CMyDownloader()
{
    iSession.Close();
    iConnection.Close();
    iSocketServ.Close();
}

void CMyDownloader::ConstructL()
{
    iSession.OpenL();
}

void CMyDownloader::SetHeaderL(
        RHTTPHeaders aHeaders,
        TInt aHdrField,
        const TDesC8& aHdrValue)
{
    RStringF valStr = iSession.StringPool().
        OpenFStringL( aHdrValue );
    CleanupClosePushL( valStr );
    THTTPHdrVal val( valStr );
    aHeaders.SetFieldL( iSession.StringPool().
        StringF( aHdrField,
        RHTTPSession::GetTable() ), val );
    CleanupStack::PopAndDestroy( &valStr );
}

void CMyDownloader::HandleRunErrorL(
            TInt aError ) { }

void CMyDownloader::StartDownloadL(
        const TDesC8& aUri)
{
    User::LeaveIfError(iSocketServ.Connect());
    User::LeaveIfError(iConnection.Open(iSocketServ));
    User::LeaveIfError(iConnection.Start());

    RStringPool strPool = iSession.StringPool();
    RHTTPConnectionInfo connInfo =
            iSession.ConnectionInfo();

    connInfo.SetPropertyL (
        strPool.StringF(HTTP::EHttpSocketServ,
        RHTTPSession::GetTable() ), THTTPHdrVal
        (iSocketServ.Handle()) );

    connInfo.SetPropertyL (
        strPool.StringF(HTTP::EHttpSocketConnection,
        RHTTPSession::GetTable() ),
        THTTPHdrVal (
        REINTERPRET_CAST(TInt, &(iConnection))) );
    TUriParser8 uri;
    uri.Parse( aUri );

    RStringF method = iSession.StringPool().StringF(
         HTTP::EGET, RHTTPSession::GetTable());

    iTransaction = iSession.OpenTransactionL( uri,
        *this, method );

    RHTTPHeaders hdr = iTransaction.Request().
        GetHeaderCollection();
    SetHeaderL( hdr, HTTP::EUserAgent, KUserAgent );
    SetHeaderL( hdr, HTTP::EAccept, KAccept );

    iTransaction.SubmitL();
}


void CMyDownloader::CancelTransactionL()
{
    iTransaction.Close();
}

void CMyDownloader::MHFRunL(
        RHTTPTransaction aTransaction,
        const THTTPEvent& aEvent)
{
    switch ( aEvent.iStatus )
    {
        case THTTPEvent::EGotResponseBodyData:
            {
            MHTTPDataSupplier* body =
                aTransaction.Response().Body();
            TPtrC8 dataChunk;
            TBool isLast = body->GetNextDataPart(
                dataChunk);
            iObserver.ClientBodyReceived(dataChunk);
            body->ReleaseData();
            }
            break;
        case THTTPEvent::ESucceeded:
            {
            aTransaction.Close();
            }
            break;
        case THTTPEvent::EFailed:
            {
            aTransaction.Close();
            }
            break;
        default:
            if ( aEvent.iStatus < 0 )
            {
                aTransaction.Close();
            }
            break;
        }
    }

TInt CMyDownloader::MHFRunError(TInt aError,
         RHTTPTransaction aTransaction,
         const THTTPEvent& aEvent)
{
    return KErrNone;
}