Re: [Cppcms-users] CppCMS and QT
Brought to you by:
artyom-beilis
|
From: Frank E. <fra...@an...> - 2011-01-03 08:59:55
|
hi artyom,
thank you very much - this worked in deed :)
regards
frank
Am 30.12.2010 22:10, schrieb Artyom:
>>
>> my actual problem is that i want to use the QNetworkAccessManager in a
>> cppcms application object to perform an external https call which is
>> required for an authentication to an external 3rd party provider.
>> actually i do something like this in the cppcms application object:
>>
>> QNetworkAccessManager * nmgr = new QNetworkAccessManager();
>> QNetworkReply * nrep = nmgr->get(QNetworkRequest(url));
>> if(!nrep->waitForReadyRead(30000)) {
>> // read failed
>> } else {
>> QByteArray json = nrep->readAll();
>> // do something with the json data..
>> }
>>
>> when i run this i get the following runtime error from qt:
>>
>> QObject::startTimer: QTimer can only be used with threads started with
>> QThread
>>
>> this must originate inside the waitForReadyRead call since the
>> QNetworkAccessManager works asynchronous..
>>
>> the problem according to the error message must be that the thread is
>> not created through QThread and therefore misses some supplemental data
>> which hinders QTimer on working. so my first thought was to gt the
>> cppcms application somehow inside a QThread. of course i have no idea if
>> that's possible at all..
>
> I had found this:
>
> http://doc.trolltech.com/qq/qq27-responsive-guis.html#waitinginalocaleventloop
>
> Basically it is an example you may use as draft.
>
> You need to have QCoreApplication created.
>
> This simple example taken from Qt site works fine, even
> not from the main thread:
>
> #include<QNetworkAccessManager>
> #include<QNetworkReply>
> #include<QNetworkRequest>
> #include<QUrl>
> #include<QEventLoop>
> #include<QTimer>
> #include<QCoreApplication>
> #include<iostream>
>
>
> void *func(void *)
> {
> QNetworkAccessManager manager;
> QEventLoop q;
> QTimer tT;
>
> tT.setSingleShot(true);
> QObject::connect(&tT, SIGNAL(timeout()),&q, SLOT(quit()));
> QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)),
> &q, SLOT(quit()));
> QNetworkReply *reply = manager.get(QNetworkRequest(
> QUrl("http://www.google.com")));
>
> tT.start(5000); // 5s timeout
> q.exec();
>
> if(tT.isActive()){
> // download complete
> std::cout<< reply->readAll().data()<< std::endl;
> tT.stop();
> } else {
> std::cout<< "Timeout"<< std::endl;
> // timeout
> }
> return 0;
>
> }
>
>
> int main(int argc,char **argv)
> {
> QCoreApplication app(argc,argv);
> pthread_t pid;
> pthread_create(&pid,0,func,0);
> pthread_join(pid,0);
>
> }
>
> Best,
> Artyom
>
>
>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment, and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> Cppcms-users mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cppcms-users
--
Dipl.-Ing. (FH) Frank Enderle
anamica GmbH
Beinsteinerstr. 6
71334 Waiblingen
Mobil: +49 151 14981091
Telefon: +49 7151 1351565 1
Telefax: +49 7151 1351565 9
E-Mail: fra...@an...
Internet: www.anamica.de
Handelsregister: AG Stuttgart HRB 732357
Geschäftsführer: Yvonne Holzwarth, Frank Enderle
|