NOTE: I was able to do that on QtWebKit QML using the QtWebView extension. Here I am interested in using QtWebEngine.
My simple test application
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtWebEngine 1.0
ApplicationWindow {
width: 800
height: 600
color: "lightgray"
visible: true
WebEngineView {
id: webview
url: "http://stackexchange.com/"
anchors.fill: parent
}
}
How do I pass a different User Agent string?
I'm interested in using QtWebEngine too. And I can suggest you use QtWebEngine developers Trello.
As you can see in Todo for 5.5 this is currently under development and may be done in 5.5.
From Qt 5.5 onwards, you can set the WebEngineProfile.userAgent property.
// import QtWebEngine 1.4
WebEngineView {
id: webview
url: "http://stackexchange.com/"
anchors.fill: parent
profile: WebEngineProfile{
httpUserAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"
}
}
Related
I am doing an App in QML / QT / C++ (to train myself for an internship). I need to open a FileDialog in order to choose a folder location but I get an error when writing the line selectFolder: true.
I found this property here https://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html#selectFolder-prop
It's weird because I can't set selectExisting and selectMultiple either.
The documentation said we have to specify these before opening the Dialog. I did this, I don't understand.
Can anyone help me fix this error ?
Here is what I import in main.qml: import QtQuick.Dialogs 1.3
Thank you very much. Have a good day.
Here is the code:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Dialogs 1.3
Window {
id: mainWindow
visible: true
width: 700
height: 500
// FileDialog
FileDialog {
id: fileDialog
title: "Please choose a file"
folder: shortcuts.home
selectFolder: true
onAccepted: {
console.log("You chose: " + fileDialog.fileUrls)
//acceptDialog();
}
onRejected: {
console.log("rejected")
//rejectDialog();
}
Component.onCompleted: visible = true
}
}
It's not the entire code (+ 200 lines)
Image from Qt Creator
For me, the code worked fine.
Just try to delete and then put the line again.
Sometimes qml gives you these kinds of errors for no reason. Just try to run it. If there are some errors, post them
I resolved the problem.
My Qt Project version was 5.12, I created a new project with Qt 5.14 and it worked.
Thanks.
I try to use the SystemTrayIcon in QML using Qt 5.11 (Manjaro with KDE), but when i add
import Qt.labs.platform 1.1
to the QML Code (or 1.0) it doesn't show anything but instantly fails with
/path/to/project exited with code 255
Code example for empty quick project:
import QtQuick 2.11
import QtQuick.Window 2.11
import Qt.labs.platform 1.1
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
}
Problem was conflicting namespaces. Using the import like
import Qt.labs.platform 1.1 as LabsPlatform
LabsPlatform.SystemTrayIcon {
}
works just fine.
In Addition I had to include widgets and use QApplication instead of QGuiApplication.
I am new to QT and want to develop a QT Quick app for the raspberry pi and its touch LCD display. The app should have several screens (sorry, not sure what the right terminology is, with screen I mean a state of the app which fills the whole display of the Raspberry Pi) and there should be buttons to switch between those screens. How is it possible to switch to a different screen when I press a button?
I tried using loader but (right now I am testing on the Desktop not the Raspberry) it opens the qml file in a new window, but I would like to have the content of the original window replaced.
Edit:
Yes, I plan using EGLFS. I enclose some code which does in principle what I want. However, I am not sure if this is the right way to do things: I put the screens I want to have into their own qml file, and toggle their visibility through buttons our mouse areas:
main.qml
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 800
height: 460
title: qsTr("Hello World")
Page1 {
id: page1
visible: true
}
Page2 {
id: page2
visible: false
}
}
Page1.qml
import QtQuick 2.7
import QtQuick.Controls 2.0
Item {
Button {
id: button1
width: 200
height: 40
text: qsTr("To second page")
onClicked: {
page2.visible=true
page1.visible=false
}
}
}
Page2.qml
import QtQuick 2.3
import QtQuick.Window 2.2
Item {
Text {
id: text1
x: 181
y: 153
text: qsTr("Second Page")
font.pixelSize: 12
}
Rectangle {
id: rectangle
x: 252
y: 222
width: 200
height: 200
color: "#000000"
border.color: "#f12525"
}
MouseArea {
id: mouseArea
x: 234
y: 209
width: 244
height: 225
onClicked:{
page1.visible=true
page2.visible=false
}
}
}
I would venture to guess that most likely you want to use Qt5's eglfs mode on the raspberry pi. This gets rid of the normal desktop and runs your Qt5 (regular or QML) app full screen. When I last did this, I needed to compile Qt5 myself. That is something you will either want to figure out cross compiling for, or use a RaspberryPi 3 (the results can then be copied to slower Raspberry Pis if desired). I worked from the guide at https://wiki.qt.io/RaspberryPi2EGLFS
It was pretty trivial to run the program then in a window on a linux desktop or full screen on a Raspberry Pi with touch screen (both the special 7" screen or a generic 22" touch display).
A newer looking alternative to using eglfs is apparently the QtWayland Compositor. I haven't used it, but there is an interesting presentation on using it for full screen embedded applications from the most recent (2017) FOSDEM, available here: https://fosdem.org/2017/schedule/event/device_specific_compositors/
I got this piece of code:
import QtQuick 2.7
import QtQuick.Controls 1.5
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("spinbox trouble")
SpinBox{
anchors.centerIn: parent
value: 5
minimumValue: 1
maximumValue: 10
}
}
Everything is fine. Now I want to use SwipeView. To use it I need use QtQuick.Controls 2.1. But when I use version 2.1, I cannot find [minimum/maximum]Value in SpinBox.
Questions:
1. What is reason to drop this properties in QtQuick.Controls 2.1?
2. Is there any way to use both SwipeView and SpinBox with [minimum/maximum]Value property?
Looking at the Qt doc I'd say you can use the from and to properties instead of minimumValue and maximumValue!?
I'm unable to loop a media (mp4 or mp3) with Qt5.4 64 bits (gcc & clang) under Ubuntu 14.04, using QML MediaPlayer. I can't even simply replay the video or audio, it can be played once, that's all.
I add that the problem does not occur under windows 7 64 bits with Qt5.3 (mingw & msvc2012).
Here the simple test code I use :
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtMultimedia 5.0
Item {
width: 640
height: 480
MediaPlayer {
id: video
loops: 2
source : "qrc:si_blue"
}
MediaPlayer {
id: audio
loops: 2
source : "qrc:check"
}
VideoOutput {
id: output
source : video
}
Button {
id: btn
width : 30
height: 30
onClicked: audio.play()
} }