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()
} }
Related
I want to have a rectangle that has a background animation.
take a look at this
codepen.io/shshaw/pen/DxJka
How can I set this as my rectangle background so that it shows this animation in my application?
I want to be able to "load" premade css animations like the one in the link.
If you think to use css, you can use a WebView and in this WebView you can load a html file from resource that read css file from resources too
Within QML there is the possibility to use particle emitters, see Qt Docs for some information. The following should get you going a bit.
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.4
import QtQuick.Particles 2.0
Item {
Rectangle {
color: "#F9A72B"
anchors.fill: parent
}
ParticleSystem { id: particles }
ImageParticle {
system: particles
source: "qrc:/cloud.svg"
alpha: 0.4
alphaVariation: 0.2
}
Emitter {
system: particles
emitRate: 1
lifeSpan: 70000
velocity: PointDirection { x: -10; xVariation: -5; }
size: 20
sizeVariation: 10
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 5
}
}
Obviously, you will have to play with the parameters to get it to your liking.
I am unable to use QGamepad in QML under Linux.
By "unable" I mean no gamepad signal is emitted (button pressed...)
Configuration:
Ubuntu 20.04
Qt 5.15
Logitech Gamepad F310
Gamepad is well recognized by Ubuntu:
dmesg gives:
usb 1-1.6: Product: Gamepad F310
input: Logitech Gamepad F310 as /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.6/1-1.6:1.0/input/input26
jstest-gtk recognizes gamepad well:
Logitech Gamepad F310
Device: /dev/input/js0
and is responsive when pressing buttons
Sample QML code:
import QtQuick 2.15
import QtGamepad 1.15
Rectangle {
width: 320
height: 240
Gamepad {
onButtonAChanged: {
console.log("ButtonA")
}
onButtonBChanged: {
console.log("ButtonB")
}
}
}
I tried to define QT_GAMEPAD and QT_GAMEPAD_DEVICE env variables, but without any improvment.
export QT_GAMEPAD=evdev
export QT_GAMEPAD_DEVICE=/dev/input/js0
Note: the same QML code is working well under MS Windows 10 (same Qt version).
Thanks to Jack White this is the solution:
Property deviceId of Gamepad module shall be initialized, using GamepadManager.
import QtQuick 2.15
import QtGamepad 1.15
Rectangle {
width: 320
height: 240
Gamepad {
deviceId: GamepadManager.connectedGamepads.length > 0 ? GamepadManager.connectedGamepads[0] : -1
onButtonAChanged: {
console.log("ButtonA");
}
onButtonBChanged: {
console.log("ButtonB");
}
}
}
It's troubling me building an array of objects with a lot of data in qml using the Windows platform (it's the only one that the crash happens). For some reason the application is crashing if the processing function takes too long!
I'm going to illustrate with a portion of code what i want to do:
main.qml
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
id: window
title: "Stack"
visible: true
width: 1400
Page {
id: page
anchors.fill: parent
property int responsiveWidth: 1000
property int maximumWidth: 900
ScrollView {
id:configScroll
anchors.fill: parent
GridLayout {
columns: 2
width: page.width > page.responsiveWidth ? page.maximumWidth : page.width
anchors.top: parent.top
anchors.left: parent.left
anchors.leftMargin: page.width > page.responsiveWidth ? (page.width - childrenRect.width)/2 : 10
anchors.rightMargin: page.width > page.responsiveWidth ? 0 : 10
Button {
property bool test: true
text: "array func"
onClicked: {
var panelModes=[], rows=[],groupsModes=[], panelLabel="panel", sounderLabel="sounder",soundersModeLabel="sounder mode",sounderGroupLabel="sounder group"
for(var gSndrModeAdd=0; gSndrModeAdd<1000;gSndrModeAdd++) {
panelModes = []
for(var pSndrModeAdd=0; pSndrModeAdd<32; pSndrModeAdd++) {
rows = []
rows.push(["C1",1])
rows.push(["C2",1])
for(var sSndrModeAdd=0; sSndrModeAdd<32; sSndrModeAdd++) {
rows.push(["L1S"+(sSndrModeAdd+1),1])
rows.push(["L2S"+(sSndrModeAdd+1),1])
rows.push(["L3S"+(sSndrModeAdd+1),1])
rows.push(["L4S"+(sSndrModeAdd+1),1])
}
panelModes.push({"label":panelLabel, "value": 1, "headers":[sounderLabel,soundersModeLabel],"rows":rows})
}
groupsModes.push({"label":sounderGroupLabel,"value":1,"nested":panelModes})
}
console.log("the array is: ")
console.log(groupsModes)
}
}
}
}
}
}
This crashes.
If this is not specifically an array problem, is this memory related problem? something like that?
This is necessary to build the structure i want. Is there a way to solve this?
The error i get on console:
09:45:07: The program has unexpectedly finished.
09:45:07: The process was ended forcefully.
09:45:07: C:/Dev/QT/build-array-crash-limit-Desktop_Qt_5_11_1_MinGW_32bit-Debug/debug/array-crash-limit.exe crashed.
I managed to catch Memory usage with QML Profiler if i set the first for cycle to 300.
you have a bug here
...
for(var pSndrModeAdd=0; 32; pSndrModeAdd++) {
...
and the loop will run forever. Change to
...
for(var pSndrModeAdd=0; pSndrModeAdd<32; pSndrModeAdd++) {
...
Anyway, arrays in QML are just JavaScript arrays, as such have (practically) no maximum size.
It turns out the crashing of the application only happens on the windows platform.
In MACOS and LINUX it only blocks for the time of the function processing.
Maybe it really is a memory problem after all, that happens on windows using versions of QT that use MinGW 32-bit.
The solution to solve this problem?
The usage of MinGW 64-bit.
I have a program in Qt/Qml that uses a FolderListModel to list qml files in a folder
FolderListModel {
id: progModel
folder: "file:///" + application.dirPath()
Component.onCompleted: console.log("folder: " + folder)
}
This model is passed to a ListView
ListView{
id: gridContent
model: progModel
delegate: progDelegate
}
It works well when the application runs in the Windows host, however if I share the application folder and try to run it from other Windows OS then the application fails to detect the folder.
Now we are using the Qt 5.9.3 and QtQuick 2.3. Before it worked well, when it was used Qt 5.5 and QtQuick 1.0
Note: If I put the URL showed from the console.log, something like "file://my_remote_path" the Windows Explorer open the folder correctly.
I have written a small piece of code to make the problem more clear
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import Qt.labs.folderlistmodel 2.1
ApplicationWindow {
visible: true
width: 640
height: 600
title: qsTr("Hello World")
SwipeView {
id: swipeView
anchors.fill: parent
Page {
Rectangle{
id: rect1
color: "#cccccc"
anchors{top: parent.top; horizontalCenter: parent.horizontalCenter}
width: parent.width * 0.6
height: parent.height*0.9
FolderListModel{
id: progfolder
showDirs: true
showDirsFirst: true
folder: "file://quatro/visao/qml/reportDialog" // It does not work
//folder: "file:///programming/comm5-qt5.6/visao/test/qml/reportDialog" // It works
//folder: "file:///programming/comm5-qt5.6/visao/reportDialog.lnk" // It works
nameFilters: ["*.qml"]
Component.onCompleted: console.log("folder " + folder)
}
ListView{
id: lv
anchors.fill: parent
model: progfolder
delegate: progDelegate
}
Component{
id: progDelegate
Text{
text: fileName
}
}
}
}
}}
This time I run the program say in PC2 but set the folder property to a shared folder in PC1, say "file://quatro/visao/qml/reportDialog". The problem is the same.
I have also comment two other ways to set the folder property. If I choose a local folder there is no problem. If I use a link to the share folder it also works but if I try to set the remote path it does not work.
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/