Results 1 to 3 of 3

Thread: Qwebview read data from gogle maps

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    22
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Qwebview read data from gogle maps

    Hi,

    I want to load google maps to qwebview from Html file and read longitude and latitude values. There is some problems with QWebView and google maps API v3. You can't use mouse to navigate in map by default. Here I have found solution http://developer.qt.nokia.com/forums...643/P15/#36423 but if I use this solution, then I can't read information from HTML file. Here is code:
    map.h
    Qt Code:
    1. #ifndef MAP_H
    2. #define MAP_H
    3. #include <QWebView>
    4. #include <QNetworkAccessManager>
    5. #include <QWebFrame>
    6. #include <qobject.h>
    7. class Map : public QWebView
    8. {
    9. Q_OBJECT
    10. public:
    11.  
    12. explicit Map(QWidget *parent = 0);
    13. public slots:
    14. void loadMap();
    15.  
    16. void doSomething( const QString &param );
    17. int doSums( int a, int b );
    18.  
    19. private:
    20. QNetworkAccessManager *manager;
    21. int pendingRequests;
    22. private slots:
    23. void attachObject();
    24.  
    25. };
    26.  
    27. #endif // MAP_H
    To copy to clipboard, switch view to plain text mode 

    map.cpp
    Qt Code:
    1. #include "map.h"
    2. #include "ui_mapwindow.h"
    3. #include <QDebug>
    4.  
    5.  
    6. class myWebPage : public QWebPage
    7. {
    8. virtual QString userAgentForUrl(const QUrl& url) const {
    9. return "Chrome/2.0";
    10. }
    11. };
    12.  
    13. Map::Map(QWidget *parent) :
    14. QWebView(parent) , pendingRequests(0)
    15. {
    16. manager = new QNetworkAccessManager(this);
    17. attachObject();
    18. connect( this->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(attachObject()) );
    19. //this->setPage( new myWebPage() );
    20.  
    21. }
    22. void Map::loadMap()
    23. {
    24. this->setUrl(QUrl("map.html"));
    25. this->show();
    26. }
    27. void Map::attachObject()
    28. {
    29.  
    30. this->page()->mainFrame()->addToJavaScriptWindowObject( QString("MyApi"), this );
    31. }
    32.  
    33. void Map::doSomething( const QString &param )
    34. {
    35. qDebug() << "doSomething called with parameter " << param;
    36. }
    37.  
    38. int Map::doSums( int a, int b )
    39. {
    40. return a + b;
    41. }
    To copy to clipboard, switch view to plain text mode 

    The problem is. If I will uncomment //this->setPage( new myWebPage() ); line, then google maps will function well. But i will not get data from HTML file. If I will comment this line //this->setPage( new myWebPage() ); Then I can't navigate in maps using mouse. but I will get something like this
    doSomething called with parameter "Hello from JS!!!!" (because I have added this line MyApi.doSomething( 'Hello from JS!!!!' ); in HTML file)

    I believe I have done something wrong with this part
    class myWebPage : public QWebPage
    {
    virtual QString userAgentForUrl(const QUrl& url) const {
    return "Chrome/2.0";
    }

    But don't know what. I can post all code with HTML code if that would help more. Thank you.

  2. The following user says thank you to Tadas for this useful post:

    TheIndependentAquarius (4th June 2011)

Similar Threads

  1. QWebView Problem Drag&Drop Markers in Google Maps
    By MightTower in forum Qt Programming
    Replies: 3
    Last Post: 29th April 2011, 23:19
  2. Exists any method to move data into STL::MAPS ???
    By tonnot in forum General Programming
    Replies: 2
    Last Post: 18th April 2011, 17:22
  3. Replies: 2
    Last Post: 16th June 2010, 15:42
  4. Posting data to QWebView
    By chrisb123 in forum Newbie
    Replies: 5
    Last Post: 29th October 2009, 06:58
  5. can`t read a binary data!
    By blm in forum Qt Programming
    Replies: 8
    Last Post: 18th September 2008, 16:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.