Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Chinese
  4. QWebengineView 無法使用 Google Map APIs?
Qt 6.11 is out! See what's new in the release blog

QWebengineView 無法使用 Google Map APIs?

Scheduled Pinned Locked Moved Unsolved Chinese
1 Posts 1 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EdXian
    wrote on last edited by EdXian
    #1

    大家好:
    目前想做一個關於GPS結合Qt的小專案,目前選擇Google Map作為我的地圖,在使用QWebengineView時事可以順利載入地圖的,但我無法使用 webview->page()->runjavascript() 去操作Javascript內的function 程式碼 。

      QUrl url("qrc:/map.html");
    
           QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::PluginsEnabled,true);
           QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::JavascriptEnabled,true);
           QWebEnginePage *page = new QWebEnginePage(this);
           QWebChannel *channel = new QWebChannel(this);
           page->load(url);
           page->setWebChannel(channel);
           ui->widget->setPage(page);
    
            QString js=QString("var marker = new google.maps.Marker({ ")+
            QString("position: new google.maps.LatLng(24.705311, -74.2581939),")+
            QString(" map: map,")+
            QString("title: \"Marker A\",")+
            QString("   }); ");
    
           ui->widget->page()->runJavaScript(js,[](const QVariant &result){ qDebug() << result.toBool(); });
    
    錯誤回報:
    js: Uncaught ReferenceError: google is not defined
    

    目前才剛接觸Qt 的Web功能和javascript,所以也不知道問題出在哪裡?
    另外有人可以提供關於webchannel的範例嗎?
    謝謝大家!!

    開發環境: 
    Ubuntu 16.04
    Qt 5.7
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved