QMouseEvent and Qt WebKit
-
Hi,
I tried that example http://stackoverflow.com/questions/2034981/how-to-manipulate-pages-content-inside-webkit-window-using-qt-and-qtwebkit and it works except the QMouseEvent part. Because it is from 2010 maybe something change in Qt :s
Anyone know how to perform the mouse event?
I want to go to next page and doesn't need to use the QMouseEvent maybe there are other options.Thanks,
José Xavier -
Hi,
Could you post more details? For instance
- which Qt version does you use
- do you have URL or you would like to press (click) on specific position of page
BR,
-
My final goal is to do what I describe here: http://qt-project.org/forums/viewthread/19791/
I want my application to be able reboot the router autonomous. My idea is to open the router webpage in a qwebview and going from page to page to the reboot button. I'm still think and I'll do it but one option is to record where the user click and after perform the same clicks. I think it can be done using request and http post...About that example http://stackoverflow.com/questions/2034981/how-to-manipulate-pages-content-inside-webkit-window-using-qt-and-qtwebkit is just the QMouseEvent that doesn't work, i'm using the page www.google.com to test.
-
Should the recorded steps be done in visible form or not? If not, you can simply subclass QNetworkAccessManager and reimplement createRequest function in which you'll save all requests in sequence. Subclass QWebPage and set your new QNAM in constructor. After that you can simply use QNAM without QWebView/QWebPage to play the whole saved request again...
-
[quote author="AcerExtensa" date="1345792917"]Should the recorded steps be done in visible form or not? If not, you can simply subclass QNetworkAccessManager and reimplement createRequest function in which you'll save all requests in sequence. Subclass QWebPage and set your new QNAM in constructor. After that you can simply use QNAM without QWebView/QWebPage to play the whole saved request again...[/quote]
Thanks :)
The record phase will visible and following your idea I found an example that do what you describe :) http://blogs.kde.org/node/4210
When the application need to play the recorded request it doesn't need to be visivle.I need to save all the requests or should I look to a specif type of requets? Because it include request to images etc...
If you can explain me a little more about I'll make QNAM "request" my requests it will be great :)Thanks :)
-
You can do it by two ways:
- maybe the easiest way: subclass QWebPage and reimplement virtual function "acceptNavigationRequest":http://doc-snapshot.qt-project.org/4.8/qwebpage.html#acceptNavigationRequest
In your code, right after you have created QWebView, set your subclassed webpage
@view->setPage(webpage);@You will actually need only two types to save: link clicked and form submitted
@
type == QWebPage::NavigationTypeLinkClicked
type == QWebPage::NavigationTypeFormSubmitted
@Save Url, Type(GET/POST), Headers and Data if it is an POST request to the file. Like:
@url:<url>\n
type:<1-get|2-post>\n
headers:<header-pair1;header-pair2;etc>\n
data:<read this if type == 1 BASE64>\n
#############################
url:<url>
....
#############################
...@After that, open this file and read data to QNetworkRequest set it to QNAM and fire post or get function, in finished slot check if it has no error, read next request from file and do that again...
- subclass QNAM and reimplement virtual function "createRequest":http://doc-snapshot.qt-project.org/4.8/qnetworkaccessmanager.html#createRequest
In your code, right after you have created QWebView, set your subclassed QNAP to webpage
@view->page()->setNetworkAccessManager(qnam);@You will get all kind of request, for images, css, flash, external files etc... you can when sort them here and save for example the same way like in method 1.
You should test the first method, if it will not work try the second one... and post your code if something goes wrong... For some webpages you will need to implement cookies too...
-
thanks for that excelent explanation ;) PS: all the code that I'm developing will be post as OSS so it can help other too.
I re-implement acceptNavigationRequest as you said like:
@MyWebPage::MyWebPage()
{
}bool MyWebPage::acceptNavigationRequest ( QWebFrame * frame, const QNetworkRequest & request, NavigationType type ){
qDebug()<<request.url()<<type; return true;
}@
And the first problem I saw is that I don't know how I'll define the user and pass of the website.
QUrl( "http://192.168.1.1/" ) QWebPage::NavigationTypeOther -> this is the homepage.
QUrl( "http://192.168.1.1/Forms/rpAuth_1" ) QWebPage::NavigationTypeFormSubmitted -> This is when I submite login after fill the user and password inputs.
QUrl( "http://192.168.1.1/rpSetup.html" ) QWebPage::NavigationTypeFormSubmittedWill I need to use QNAM? If the user need to insert the login data manually it is ok.
thanks :)
-
If you "record" your activity, username & password which you have typed on webpage will be in the data section of POST request. But I see, you can't get data section from QNetworkRequest, so you should take the second method with QNAM subclassing, there you will get QNetworkRequest and the data, but you will need to filter the image requets and etc by yourself... or maybe you can somehow use booth methods to filter request and get data section....