How to use QWebView with Qt 5.3.1 ?



  • Hi,
    I just wanted to display and listen this "web radio page":http://www.caenfm.net in a QtWebView.
    My code is minimalistic:
    QWebView2.pro
    @QT += core gui
    QT += webkitwidgets
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = QWebView2
    TEMPLATE = app
    SOURCES += main.cpp
    mainwindow.cpp
    HEADERS += mainwindow.h
    FORMS += mainwindow.ui
    @

    main.cpp
    @#include "mainwindow.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec&#40;&#41;;
    

    }@

    mainwindow.h
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QWebView>
    #include <QWebSettings>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    private slots:
    private:
    Ui::MainWindow *ui;
    };
    #endif // MAINWINDOW_H@

    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
    QUrl url("http://www.caenfm.net");
    ui->webView->load(url);
    ui->webView->adjustSize();
    this->setFixedWidth(ui->webView->width());
    this->setFixedHeight(200); //---> The height is variable
    }
    MainWindow::~MainWindow()
    {
    delete ui;
    }@

    mainwindow.ui
    @[...]
    <widget class="QWidget" name="centralWidget">
    <widget class="QWebView" name="webView">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>300</width>
    <height>200</height>
    </rect>
    </property>
    <property name="url">
    <url>
    <string>about:blank</string>
    </url>
    </property>
    </widget>
    </widget>
    [...]@

    In the web page, that is the object "On Air" witch "generates" the sound.

    !http://www.selzig.com/1408132100/object.png(Object HTML)!
    @<div>
    <div class="widget-content">
    <object width="240" height="300">
    <param name="allowscriptaccess" value="always" />
    <param name="movie" value="http://static.radionomy.com/cdn/flash/BannerEmbed.swf?RadUID=69ee2bc8-8ae4-4658-9256-94e2fd4f5482&titlesColor=000000&color=f20000&autoPlay=yes&lang=fr" />
    <param name="wmode" value="transparent" />
    <embed src="http://static.radionomy.com/cdn/flash/BannerEmbed.swf?RadUID=69ee2bc8-8ae4-4658-9256-94e2fd4f5482&titlesColor=000000&color=f20000&autoPlay=yes&lang=fr" wmode="transparent" type="application/x-shockwave-flash" allowscriptaccess="always" width="240" height="300"></embed>
    </object>
    </div>
    </div>@

    I note that at least a part of "On Air" object should be visible on the QWebView to listen for the sound generated by the swf.

    initial test : this->setFixedHeight(200);
    "On air" is not visible : Display OK - No sound
    !http://www.selzig.com/1408132100/nosound.png(height = 200)!

    After using the vertical scroll to make the "On Air" appear, the sound is OK.
    !http://www.selzig.com/1408132100/vscroll.png(height = 200-after vscroll)!

    Second test : this->setFixedHeight(400);
    "On Air" is directly apparent : Sound OK.
    !http://www.selzig.com/1408132100/sound.png(height = 400)!

    Is it a normal behaviour ? So how do you get around that to get the sound whatever the size of the QWebView ?

    Regards. Gilles
    PS : Qt 5.3.1 : Identical issues when running on Windos 7-32 (VS2010-x86), Windows 7-64 (VS2013-amd64), Ubuntu 14.04-32 and Ubuntu 14.04-64


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.