[Qt-interest] In need of help in qtwebkit, QNetworkAccessManager and QNetworkReply
Zaid Amir
z.alamir at genie-soft.com
Sun Feb 28 12:19:44 CET 2010
Yes they do and actually I copied their decleration directly from
qiodevice.h just to be sure..
The problem seems that webview is not issuing a read operation to my class,
when right-clicking on the view I get a stop option rather than a reload,
when I click stop my abort() implementation gets called but webkit is not
calling any of my other methods, bytesAvailable and readData()... I am not
sure if there is a trick that I should do from webview itself.. All I'm
doing is setting the page() NetworkAccessManager to my NAM using this code:
<Code>
QNetworkAccessManager *oldManager = webView->page()->networkAccessManager();
NetworkAccessManager *newManager = new NetworkAccessManager(oldManager,
this);
webView->page()->setNetworkAccessManager(newManager);
</code>
where: webView is my QWebView object;
and in the createRequest method of my QNetworkAccessManager implementation
I'm checking the scheme of the url and then creating a new object of my
QNetworkReply implementation and returning it.
Any suggestions...
-----Original Message-----
Message: 1
Date: Sun, 28 Feb 2010 10:52:37 +0100
From: Andr? Somers <andre at familiesomers.nl>
Subject: Re: [Qt-interest] In need of help in qtwebkit,
QNetworkAccessManager and QNetworkReply
To: <qt-interest at trolltech.com>
Message-ID: <016e01cab85b$c5f939e0$51ebada0$@nl>
Content-Type: text/plain; charset="iso-8859-1"
Are you sure your virtual functions have the exact same signature (including
const's!) as the methods you're reimplementing in your subclass?
Andr?
-----Oorspronkelijk bericht-----
Van: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] Namens Zaid Amir
Verzonden: zondag 28 februari 2010 8:46
Aan: qt-interest at trolltech.com
Onderwerp: Re: [Qt-interest] In need of help in qtwebkit,
QNetworkAccessManager and QNetworkReply
Hi
Its been a while and I'm still trying to solve the same problem.... After
lots of trials and errors and even more research on the matter I have found
that webkit is not calling any of my virtual functions. Its like as if
webkit is not seeing my reply. I am not sure why or how this is happening.
Please if anyone has the faintest idea about what might be causing this
behavior please respond.
Regards
-----Original Message-----
Message: 1
Date: Thu, 25 Feb 2010 10:57:03 +0200
From: "Zaid Amir" <z.alamir at genie-soft.com>
Subject: Re: [Qt-interest] In need of help in qtwebkit,
QNetworkAccessManager and QNetworkReply
To: "'Markus Goetz'" <Markus.Goetz at nokia.com>
Cc: qt-interest at trolltech.com
Message-ID: <000b01cab5f8$80b1c010$82154030$@alamir at genie-soft.com>
Content-Type: text/plain; charset="us-ascii"
Its been two days now and I have reached to the point that I can now read
the data correctly, however the image is not showing on the view... I am not
sure what is going wrong as I have tried writing the data to a file and the
image was created correctly... In order to make things clear, I am posting
my code hear so that hopefully someone spots the what is wrong with my
method.
CustomReply:: CustomReply (const QUrl& url): QNetworkReply()
{
hFile =
CreateFileA("C:/Users/ZAID-RS7/Pictures/The_Evil_Snowman_by_Beloved_Creature
.jpg", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
connect(this, SIGNAL(QNetworkReply::readyRead()), this,
SLOT(processData()));
//setOperation(QNetworkAccessManager::GetOperation);
offset = 0;
processRequest();
}
//I've tried setting it to false but this changed nothing
bool CustomReply::isSequential() const
{
return true;
}
void CustomReply::processRequest()
{
ProcessData();
//constent is a QByteArray and I am writing the data I got from readData to
a file and its working fine.
content = readAll();
//This is only for testing....
HANDLE hNewFile =
CreateFileA("c:/users/zaid-rs7/Desktop/newimage.jpg", GENERIC_WRITE,
FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hNewFile != INVALID_HANDLE_VALUE)
{
DWORD dwBytesWritten = 0;
BOOL bWrite = WriteFile(hNewFile, content.constData(),
content.size(), &dwBytesWritten, NULL);
CloseHandle(hNewFile);
if(bWrite)
{
int x = 0;
}
}
//End testing..... The image was created and its viewable (Not Corrupted)
setHeader(QNetworkRequest::ContentTypeHeader,
QVariant("image/jpeg"));
setHeader(QNetworkRequest::ContentLengthHeader,
QVariant(this->content.size()));
//close the IODevice.... Doesn't make a difference in behavior
close();
}
void CustomReply::ProcessData()
{
open(ReadOnly | Append);
LARGE_INTEGER intSize;
intSize.QuadPart = 0;
//Read the raw data of the image file being viewed...
if(hFile != INVALID_HANDLE_VALUE)
{
GetFileSizeEx(hFile, &intSize);
char* ImageData = new char[intSize.QuadPart];
DWORD dwBytesRead = 0;
ReadFile(hFile, ImageData, intSize.QuadPart, &dwBytesRead,
NULL);
//Converting the read data to a QByteArray
QByteArray data(ImageData, intSize.QuadPart);
ResourceData = data;
nImageSize = intSize.QuadPart;
//This part only check if the image was read successfully.... should be
removed later
HANDLE hNewFile =
CreateFileA("c:/users/zaid-rs7/Desktop/newimage2.jpg", GENERIC_WRITE,
FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hNewFile != INVALID_HANDLE_VALUE)
{
DWORD dwBytesWritten = 0;
BOOL bWrite = WriteFile(hNewFile, ImageData,
intSize.QuadPart, &dwBytesWritten, NULL);
CloseHandle(hNewFile);
if(bWrite)
{
int x = 0;
}
}
}
//Don't have any effect whatsoever...
emit readyRead();
emit finished();
}
//Not Implemented
void CustomReply::abort()
{
}
//This is rarely called.. Not sure why...
//??????????????????????????????????????
qint64 CustomReply::bytesAvailable() const
{
LARGE_INTEGER intSize;
intSize.QuadPart = 0;
if(hFile != INVALID_HANDLE_VALUE)
{
GetFileSizeEx(hFile, &intSize);
}
qint64 qnsize = intSize.QuadPart;
return qnsize - offset + QIODevice::bytesAvailable();
}
//The Read data Function..... should be working fine, unless someone can
spot an error in the algorithm...
//I don't think there's anything wrong with this because the data returned
from (readAll()) is valid and a new image file can be created with it with
no corruption
qint64 CustomReply::readData(char *data, qint64 maxSize)
{
int nSize = ResourceData.size();
if(hFile != INVALID_HANDLE_VALUE)
{
if (offset < nImageSize && nImageSize !=0)
{
qint64 number = qMin(maxSize, nImageSize - offset);
char* pData = ResourceData.data() + offset;
memcpy(data, pData/*ResourceData.constData() +
offset*/, number);
offset += number;
return number;
}
else
return -1;
}
else
return -1;
}
I am not sure what is wrong with the code here, The data seems valid.
Please if someone can spot anything wrong with what I'm doing please tell me
or give me a hint at least.
Regards.
P.S. The code is for testing purposes only, it contains memory leaks and
minimum error checking.
-----Original Message-----
From: Markus Goetz [mailto:Markus.Goetz at nokia.com]
Sent: Tuesday, February 23, 2010 5:16 PM
To: ext Zaid Amir
Subject: Re: [Qt-interest] In need of help in qtwebkit,
QNetworkAccessManager and QNetworkReply
Please let the list know, I don't have much time.. :)
ext Zaid Amir wrote:
> I will try it and let you know about any progress..
>
> thanks
>
> -----Original Message-----
> From: Markus Goetz [mailto:Markus.Goetz at nokia.com]
> Sent: Tuesday, February 23, 2010 4:59 PM
> To: ext Zaid Amir
> Subject: Re: [Qt-interest] In need of help in qtwebkit,
> QNetworkAccessManager and QNetworkReply
>
> Think about it this way:
>
> Would a real webserver return data or would it return a QImage object?
>
> ext Zaid Amir wrote:
>
>> Thx for the reply..
>>
>> Well that is the main problem I'm facing, I am not sure how to override
>>
> the
>
>> readData() function to load the image in memory....
>> Should I just memcpy the image data to the "data" pointer in readData()
or
>> should I return it as a QImage.
>>
>> Regards
>>
>> -----Original Message-----
>> From: Markus Goetz [mailto:Markus.Goetz at nokia.com]
>> Sent: Tuesday, February 23, 2010 4:52 PM
>> To: ext Zaid Amir
>> Cc: qt-interest at trolltech.com
>> Subject: Re: [Qt-interest] In need of help in qtwebkit,
>> QNetworkAccessManager and QNetworkReply
>>
>> ext Zaid Amir wrote:
>>
>>
>>>
>>>
>>> I have been trying for over a week now to try and load those images
>>> into memory and return them to my webview to be displayed. I have
>>> managed to override both QNetworkAccessManager and get the request
>>> from the currently loading page, parse the given url which is
>>> basically a special url (for example: "*/rc:image.jpg/*"), this would
>>> mean that image.jpg is currently residing in a resource file so I
>>> should search for it and return it to webview to be displayed.
>>>
>>>
>>>
>>> I am not sure how am I suppose to load the image data into memory and
>>> point my QNetworkReply object to it. I would appreciate any hint,
>>> example or idea to make this work.
>>>
>>>
>>>
>>>
>>>
>> Override QNetworkAccessManager::createRequest(..)
>> Make it handle rc: URLs special by returning a ZaidAmirNetworkReply
object
>> In the ZaidAmirNetworkReply class override the readData(..) function to
>> return data from memory or wherever you have your custom image. Also
>> make sure to set appropriate Content-Type headers in this reply.
>>
>> Hope that helps!
>> Markus
>>
>>
>>
>>
>
>
>
>
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list