QT WebView/WebKit issue - qt

I'm trying to add a WebView to my GUI. First, the app crashed unexpectedly everytime. I figured I probably needed to import WebKit 3.0 along with WebView 1.1. After adding the required import statement, I try to run but it says that module "QtWebKit" is not installed. I checked the include folder and its indeed not there.
So my question is if QtWebKit is what I need, how do I install it?
Update:
When this code exists in my .qml file, the app crashes without starting:
WebEngineView{
anchors.fill: parent
url: "http://www.google.com"
}
This is the import statement I'm using on QT 5.6:
import QtWebEngine 1.1
This is the segmentation fault error generated because of the presence of the code mentioned above:
Full demo code:
import QtQuick 2.6
import QtQuick.Controls 1.5 as QC
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.0
import QtQuick.Dialogs 1.2
import QtMultimedia 5.6
import Qt.labs.controls 1.0
import QtWebEngine 1.2
ApplicationWindow {
height: 640
width: 480
visible: true
Loader{
anchors.fill: parent
sourceComponent: webComponent
}
Component{
id: webComponent
WebEngineView{
anchors.fill: parent
id: web
profile: WebEngineProfile {
storageName: "Default"
}
}
}
}

Your debugger's stack trace shows that your crash is occurring in Qt's OpenGL functions. Remember to call QtWebEngine::initialize() before you start using Qt WebEngine.
Note also:
Qt WebView is a lightweight module for running your mobile OS's native web engine. Its main QML type is called WebView.
Qt WebKit is a heavyweight module for running a fully self-contained web engine. Its main QML type is also called WebView, but this is completely unrelated to the other WebView. This module is now deprecated.
Qt WebEngine is a heavyweight module for running a fully self-contained web engine. Its main QML type is called WebEngineView. This module is meant to replace Qt WebKit.

Qt WebKit is a deprecated module. Maybe you can install it from Qt sources, but since you want to use WebView 1.1 (and that you're on Qt5.6), I think you'd better use Qt WebEngine (using deprecated modules is not recommended).
You can already see it in your folder (modules QtWebEngine and QtWebView).

Related

Qt Creator: how to create Qt6 project?

I have installed Qt 6.0.3 and 6.1.0.
And I want to create Qt 6 Quick project.
I start Qt Creator, click "New", "Qt Quick Application - Empty", "Choose...".
Then I type the name of my project and click "Next".
On the "Build System" step I select any build system(qmake, CMake or QBS, it does not affect the next step) and click "Next".
On the next step "Details" there is a drop-down with a list of available Qt versions. But it does not contain Qt 6!
How to create Qt 6 Qt Quick project?
Latest Qt Creator's (4.14.2 at the time of answering) new project assistant does not provide the option to require Qt 6 as a minimal version yet. There is an open bug about the missing feature in Qt Bug Tracker: New project assistant: no minimal Qt version >= 6.0
However, as #JarMan already commented you actually configure your project for specific kit and selecting e.g. Qt 6.0.3 kit means that you configure and build your application against that Qt version.
In fact, minimal Qt version selection in Qt Quick application wizard affects versions of the QML import statements used in generated QML files. E.g. selecting Qt 5.12 as minimal version means that you get import QtQuick 2.12 and import QtQuick.Window 2.12 written to your main.qml. And selecting Qt 5.15 as minimal version means getting import QtQuick 2.15 and import QtQuick.Window 2.15, and so on.
In Qt 6 version numbers may be omitted from imports in QML. If the version is omitted, the latest version will be used.
Most probably it means that when Qt Creator starts supporting Qt 6 as minimal version respective generated import statements will be import QtQuick and import QtQuick.Window.
You can actually edit your generated Qt Quick application so that you manually remove version numbers from import statements if you wish. It will turn your application to minimal Qt6 application because that application cannot be built with Qt5 kits anymore.

Why is my QML code loading FileDialog from Qt.labs although I imported QtQuick.Dialogs?

I am using a FileDialog supposedly from QtQuick.Dialogs in one of my QML files. When I open the context help in QtCreator however, it shows me the entry for FileDialog from Qt Labs, no the one from Qt Quick Dialogs as expected. I have no mention of Qt Labs anywhere in my project. Why doesn't it use the FileDialog I tell it to?
I am using QtCreator 4.6.2 with Qt 5.11.1 on Ubuntu 18.04.
Here are the relevant code snippets:
LoadFileDialog.qml:
import QtQuick 2.9
import QtQuick.Dialogs 1.3
FileDialog {
id: loadFile
folder: "."
selectExisting: true
selectMultiple: false
title: "Please select file to load"
onAccepted: {
//[...]
}
onRejected: {
//[...]
}
}
Import statements in *.pro file:
QT += qml quick gui widgets
CONFIG += c++11
The application runs fine on my Ubuntu 18.04 system, from QtCreator using Qt 5.11.1 as well as stand-alone using the system's Qt 5.9. As soon as I try to run it on an Ubuntu 20.04 system with Qt 5.12 on it, it complains about not finding the FileDialog. I have no idea what library is missing to make it work either.
EDIT: The output I get when trying to run the application in Ubuntu 20.04 is:
qt5ct: using qt5ct plugin
QQmlApplicationEngine failed to load component
qrc:/main.qml:193 Type LoadFileDialog unavailable
qrc:/LoadFileDialog.qml:4 Type FileDialog unavailable
file:///usr/lib/x86_64-linux-gnu/qt5/qml/QtQuick/Dialogs/DefaultFileDialog.qml:47 module "Qt.labs.folderlistmodel" is not installed
Thanks.
You have already figured out your original question, so I will try to answer the second one.
The logic for which type of dialog is chosen is described here:
The implementation of FileDialog will be a platform file dialog if
possible. If that isn't possible, then it will try to instantiate a
QFileDialog. If that also isn't possible, then it will fall back to a
QML implementation, DefaultFileDialog.qml. In that case you can
customize the appearance by editing this file. DefaultFileDialog.qml
contains a Rectangle to hold the dialog's contents, because certain
embedded systems do not support multiple top-level windows. When the
dialog becomes visible, it will automatically be wrapped in a Window
if possible, or simply reparented on top of the main window if there
can only be one window.
This code is part of the logic that determines whether or not a native file dialog is used. This function is another part. So, to make sure you get a native file dialog, you apparently need GTK3 3.15.5 or newer. If that fails, it will fall back to a widget dialog. For that to work, your application object should also be a QApplication. Finally, a QML dialog will be used as the final fallback.

How can I know which Qt quick version in my system before importing that?

By qVersion() I will get the Qt version as 5.13.1
But in QML I use import QtQuick 2.12. How to get the QtQuick version C++/QML (2.12)?
I do not know of any way to "print the QtQuick version" (as per your comment on your question). However, reading the docs it seems that it is just a 1:1 mapping between the Qt version and the QtQuick version.
This Qt forum post appears to confirm that post:
Every new Qt release gets a new QtQuick version. It's a 1 to 1 mapping so far: Qt 5.x has QtQuick 2.x (so, Qt 5.4 has QtQuick 2.4). You can check that by opening the documentation for - for example - Rectangle or Item.
Here's the corresponding documentation that shows the mapping of the Qt version and the QtQuick(Controls) version: https://doc.qt.io/qt-5/qtquickcontrols-index.html
From that it would appear that you need to use/import QtQuick 2.13 when you're using Qt 5.13.

ScrollView with QtQuick.Controls 2.3 don't find library in QML

Today I've updated to Qt 5.9, I'm trying of use ScrollView, but this require this library: import QtQuick.Controls 2.3
When I import the library, and run, i receive this error:
QtQuick.Controls 2.3 is not installed.
This is impossibile, because I've installed last release qt 5.9
I need to use import QtQuick.Controls 2.1 to scroll content on android and ios.
Any solutions?
The documentation you link, is from the dev-branch of Qt5.10 - this will probably come with QtQuick.Controls 2.3, so the import-statement there seems legit.
Your error-message is also correct, as Qt5.9 ships with QtQuick.Controls 2.2
The documentation link of yours however states, that ScrollView is available since Qt5.9 - which is also backed by the documentation of this version, that can be found here - however then it is necessary to import the installed version QtQuick.Controls 2.2
If that does not work, I don't really see the superiority of the ScrollView over the old-style attatching ScrollBars to Flickables.

WebEngineView QML type need flash player to install

I'm using WebEngine Qt Quick Minimal Example to build a simple program to load a page contains some texts and an video which is shown using Adobe Flash Player.
I can see the video on my Google Chrome but when i try to load the page in the mentioned example, following error appear instead of Adobe Flash Player:
This video requires Adobe Flash Player 10.2
I have downloaded Adobe Flash Player plugin for every browser but no change is occurred!
Using flash player in WebEngine needs three step:
Installing Pepper Flash Player Plugin
Load plugin to QT
Enabling this feature in WebEngineView
STEP 1:
Download Pepper Flash Player Plugin from anywhere you want (Recommend you to download it from Adobe website). Pepper plugin is another version of Flash Player plugin made to be used in Chromium-based browser, e.g WebEngine. Install it like other version of this plugin.
STEP 2:
Here says that:
The Pepper Flash player plugin can be loaded automatically if it is installed in one of the following locations, depending on the platform ...
So you need no action to done this step, because install program copies necessary files.
STEP 3:
Change QtWebEngine version to 1.3 in your .qml file:
import QtWebEngine 1.3
Add following line under WebEngineView in your .qml file:
settings.pluginsEnabled : true
Your .qml file should be like this:
import QtQuick 2.0
import QtQuick.Window 2.0
import QtWebEngine 1.3
Window {
width: 800
height: 600
visible: true
WebEngineView {
anchors.fill: parent
url: "http://127.0.0.1"
settings.pluginsEnabled : true
}
}

Resources