help-cgicc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [help-cgicc] cgicc and Qt


From: Frank Büttner
Subject: Re: [help-cgicc] cgicc and Qt
Date: Fri, 27 Mar 2009 19:23:55 +0100
User-agent: Thunderbird 2.0.0.21 (Windows/20090302)

Thanks,
now it will work.
I have written an QTextStream helper class.
For all, see the class at the attachment.

Now I can use QTextStreamCGI << cgicc:XXXX :)

Frank

Igor schrieb:
> Hello Frank,
> 
> Wednesday, March 25, 2009, 3:20:38 PM, you wrote:
> 
> 
> That was a correct remark. Each cgicc Element is derived from MStreamable 
> class
> which has << operator defined only for std::ostream. That means there
> is no << operator that knows how to put HTMLBooleanElement into
> QTextStream. But you can write your own operator which would know how
> to do it.
> 
> example:
> 
>  class QTextStream{
>    public:
>    //just to compile, junk section, if QTextStream knows how to handle
>    // std::string, it wouldn't be necessary
>            QTextStream& operator << (const string& s){
>                    return *this;
>            }
>    };
> 
>    QTextStream& operator << (QTextStream& qs, const cgicc::MStreamable& obj){
>            std::stringstream c;
>            obj.render(c);
>            qs << c.str();
>            return qs;
>    }
> QTextStream qs;
> qs << cgicc::a("Send Mail").set("href", "mailto:address@hidden";);
> 
> 
> I didn't use QTextStream so there might be a better way to write
> 
> std::stringstream c;
> obj.render(c);
> qs << c.str();
> 
> I assumed QTextStream knows how to handle std::string if it is not,
> you got to rewrite QTextStream& operator << (QTextStream& qs, const 
> cgicc::MStreamable& obj)
> 
>  
> 
> FB> Hello Igor,
> 
> FB> yes , I search something like in the example,
> FB> but this will not work.
> FB> I get this error when I try to compile it:
> 
> FB> error: no match for 'operator<<' in 'ts <<
> FB> cgicc::HTMLBooleanElement<cgicc::aTag>(((const std::basic_string<char,
> FB> std::char_traits<char>, std::allocator<char> >&)(&
> FB> std::basic_string<char, std::char_traits<char>, std::allocator<char>
>>> (((const char*)"Send Mail"), ((const std::allocator<char>&)((const
> FB> std::allocator<char>*)(&
> FB> 
> std::allocator<char>()))))))).cgicc::HTMLBooleanElement<cgicc::aTag>::<anonymous>.cgicc::HTMLElement::set(((const
> FB> std::string&)(& std::basic_string<char, std::char_traits<char>,
> FB> std::allocator<char> >(((const char*)"href"), ((const
> FB> std::allocator<char>&)((const std::allocator<char>*)(&
> FB> std::allocator<char>())))))), ((const std::string&)(&
> FB> std::basic_string<char, std::char_traits<char>, std::allocator<char>
>>> (((const char*)"mailto:address@hidden";), ((const
> FB> std::allocator<char>&)((const std::allocator<char>*)(&
> FB> std::allocator<char>())))))))'
> 
> FB> This was my test code
> 
> FB> QString Test;
> FB> QTextStream ts(&Test,QIODevice::WriteOnly);
> FB> ts << cgicc::a("Send Mail").set("href","mailto:address@hidden";);
> 
> FB> Thanks for your help.
> 
> FB> Igor schrieb:
>>> Hello Frank,
>>>
>>> Wednesday, March 25, 2009, 11:01:26 AM, you wrote:
>>>
>>> FB> Hello Steve,
>>> FB> I have look at the docu for the class.
>>> FB> But the doc say, that this is for input only,
>>> FB> but my problem is the output that must be go
>>> FB> into the QTextStream.
>>>
>>>     cgicc knows nothing about the output, it is your application
>>>     that is responsible for what to do with the output cgicc produces.
>>>     You may want to put it to cout or QTextStream or whatever.
>>>
>>>     QString str;
>>>     QTextStream ts( &str, IO_WriteOnly );
>>>     ts << cgicc::a("Send Mail").set("href", "mailto:address@hidden";);
>>>
>>>     or you may try to redirect cout to QTextStream
>>>
>>>
> 
> 
> 
> 
> 

#include "qtextstreamcgi.h"

#include <sstream>
namespace QFrank
{
QTextStreamCGI::QTextStreamCGI(FILE *datei,QIODevice::OpenMode 
zugriff):QTextStream(datei,zugriff)
{  
}
QTextStreamCGI &QTextStreamCGI:: operator <<(const cgicc::MStreamable &was)
{
    std::stringstream ss;
    was.render(ss);
    QString tmp =QString::fromStdString(ss.str());
    QTextStream::operator <<(tmp);
    return *this;
}
}
#ifndef QTEXTSTREAMCGI_H
#define QTEXTSTREAMCGI_H

#include <QtCore>
#include "cgicc/MStreamable.h"

namespace QFrank
{
    class QTextStreamCGI : public QTextStream
    {
        public:
         QTextStreamCGI(FILE *datei,QIODevice::OpenMode zugriff);
         QTextStreamCGI& operator <<(const cgicc::MStreamable &was);
    };
}
#endif // QTEXTSTREAMCGI_H

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]