Results 1 to 2 of 2

Thread: WebView with QQuickWidget and QQuikView

  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default WebView with QQuickWidget and QQuikView

    Hi,

    I am trying to view an html file(google maps) with WebView on QQuickWidget. The html loads without an error(console log says that) ;but nothing is shown on QQuickWidget, just a white screen..

    When I replace QQuickWidget with QQuickView everything works fine. But since there are some issues with QQuickView on mobile platforms, I dont want to use it.

    I have attached a minimal runnable code.

    Any idea?

    Thanks in advance..

    Code looks like that:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. #ifdef WITH_QUICKWIDGET
    8. view = new QQuickWidget();
    9. ui->verticalLayout->addWidget(view);
    10. #else
    11. view = new QQuickView();
    12. QWidget* container = QWidget::createWindowContainer(view);
    13. ui->verticalLayout->addWidget(container);
    14. #endif
    15. view->setSource(QUrl::fromLocalFile(QLatin1String(":/web/weblink.qml")));
    16. mapApiKey = QString::fromLatin1("AIzaSyAOeIxkqfAs9HQrz_PY7QPz7ZzKiML7hDE");
    17. m_webDir = QDir::homePath()+QString::fromLatin1("/") ;
    18. loadHtml();
    19. }
    20.  
    21. MainWindow::~MainWindow()
    22. {
    23. delete ui;
    24. }
    25.  
    26. void MainWindow::loadHtml()
    27. {
    28.  
    29. QString htmlData = loadFileData(QString::fromLatin1(":/web/map.html"));
    30. htmlData.replace(QLatin1String("$$API_KEY"),mapApiKey);
    31. htmlData.replace(QLatin1String("$$PORT"),QLatin1String("1000"));
    32. htmlData.replace(QLatin1String("$$WEB_DIR"),QUrl::fromLocalFile(m_webDir).toString());
    33.  
    34. QString htmlfname = QString::fromLatin1("map_%1.html").arg(QDateTime::currentMSecsSinceEpoch());
    35. htmlData.replace(QLatin1String("$$MAP_HTML"),htmlfname);
    36.  
    37. m_filePath = saveFile( htmlData, htmlfname);
    38.  
    39. if(!QFileInfo::exists(m_webDir + QString::fromLatin1("jquery.min.js")))
    40. QFile::copy(QLatin1String(":/web/jquery.min.js") , m_webDir+QLatin1String("jquery.min.js"));
    41.  
    42. if(!QFileInfo::exists(m_webDir + QString::fromLatin1("label.js")))
    43. QFile::copy(QLatin1String(":/web/label.js") , m_webDir+QLatin1String("label.js"));
    44.  
    45. QObject *object = view->rootObject();
    46. QQmlProperty::write(object, QString::fromLatin1("url"), QUrl::fromLocalFile(m_filePath).toString());
    47. }
    48.  
    49. QString MainWindow::loadFileData(QString path)
    50. {
    51. QString data;
    52. QFile readfile(path);
    53. if(readfile.open(QIODevice::ReadOnly)){
    54. QTextStream txt(&readfile);
    55. data = txt.readAll();
    56. readfile.close();
    57. }
    58. return data;
    59. }
    60.  
    61. QString MainWindow::saveFile(QString htmldata, QString fname)
    62. {
    63. QString mpath= m_webDir+fname;
    64. QFile writefile(mpath);
    65. if(writefile.open(QIODevice::WriteOnly)){
    66. QTextStream txt(&writefile);
    67. txt << htmldata;
    68. writefile.close();
    69. }
    70. return mpath;
    71. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: WebView with QQuickWidget and QQuikView

    I have detected a problem. In the weblink.qml, when I replace :

    Qt Code:
    1. WebView {
    2. id: webView
    3. anchors.fill: parent
    To copy to clipboard, switch view to plain text mode 
    with:
    Qt Code:
    1. WebView {
    2. id: webView
    3. width : 1920
    4. height: 1080
    To copy to clipboard, switch view to plain text mode 

    The web page shows up on QQuickWidget correctly. But of course size of the webview is not changing dynamically in that case. So it looks like "anchors.fill: parent" is not working as expected with WebView and QQuickWidget combination.

    Is this a known bug and is there any workaround for this ? Thanks

Similar Threads

  1. Replies: 3
    Last Post: 5th July 2021, 10:49
  2. Run QtVirtualKeyboard using QQuickWidget
    By pvb in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2020, 11:02
  3. Replies: 3
    Last Post: 24th November 2016, 14:13
  4. Replies: 4
    Last Post: 8th March 2016, 18:03
  5. QQuickView or QQmlApplicationEngine or QQuickWidget
    By ustulation in forum Qt Quick
    Replies: 0
    Last Post: 18th January 2015, 14:16

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.