requestService(): no service found for - "org.qt-project.qt.camera" - qt

I tried this example from one of the qml camera tutorials.
The camera is being detected through "cheese", but is not shown through this code.
This code results in "defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.camera"
Am using Qt 5.4 with QtGstreamer 1.2
What should I look into?
import QtQuick 2.1
import QtQuick.Window 2.2
import QtMultimedia 5.4
Window
{
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Camera {
id: camera
imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
exposure {
exposureCompensation: -1.0
exposureMode: Camera.ExposurePortrait
}
flash.mode: Camera.FlashRedEyeReduction
imageCapture {
onImageCaptured: {
photoPreview.source = preview // Show the preview in an Image
}
}
}
VideoOutput {
source: camera
anchors.fill: parent
focus : visible // to receive focus and capture key events when visible
}
Image {
id: photoPreview
}
}

Related

QML QQuickText: Cannot anchor to an item that isn't a parent or sibling

When I use TumblerColumn in my Tumbler, I get QML QQuickText: Cannot anchor to an item that isn't a parent or sibling, When I use Tumbler alone the error doesn't appear. I can't figure out what is the problem with TumblerColumn.
Here is my Dialog code
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Extras 1.2
Dialog {
id: customTimerInputDialog
title: "Custom timer"
height: 150
width: 300
standardButtons: StandardButton.Ok | StandardButton.Cancel
onAccepted: {
}
onRejected: {
console.log("Rejected")
}
Column {
anchors.fill: parent
Text {
text: "Timer"
height: 40
}
Tumbler {
id: tumbler
TumblerColumn {
model: 10
}
TumblerColumn {
model: 60
}
}
}
}
TumblerColumn (TumblerStyle.qml) complete source code
...
// line 294
property Component delegate: Item {
implicitHeight: (control.height - padding.top - padding.bottom) / tumblerStyle.visibleItemCount
Text {
id: label
text: styleData.value
color: "#666666"
opacity: 0.4 + Math.max(0, 1 - Math.abs(styleData.displacement)) * 0.6
font.pixelSize: Math.round(TextSingleton.font.pixelSize * 1.25)
anchors.centerIn: parent
}
}
...
Error message
UPDATE
I get the same error with Popup QML Type
Popup {
id: popup
x: 100
y: 100
width: 200
height: 300
modal: true
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
Tumbler {
id: intervalPicker
TumblerColumn {
model: 10
}
TumblerColumn {
model: 60
}
}
}
You are mixing Qt Quick Controls 1 and 2. In your Dialog/Popup you import
QtQuick.Controls 2.2 and QtQuick.Extras 1.2. Both imports define a Tumbler, but the one from Qt Quick Extras is made to work with Qt Quick Controls 1 (see the imports in TumblerStyle.qml).
If you want to use TumblerColumn and TumblerStyle, you have to use the Tumbler from Qt Quick Extras 1.2.
If you want to use the Tumbler from Qt Quick Controls 2, you cannot use any of the tumbler facility from Qt Quick Extras 1.2.
If you need to have both Qt Quick Extras 1.2 and Qt Quick Controls 2 imported in a qml file, you need to use the as qualifier:
import QtQuick.Extras 1.2 as Extra
import QtQuick.Controls 2.2 as Controls2
...
Extra.Tumbler
{
...
}
Controls2.Tumbler
{
...
}
...

Disable mouse wheel for QML Slider

I want to be able to scroll Flickable with mouse wheel (or two fingers on touchpad) without changing Sliders it may containt.
Sample code and result application:
import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
ApplicationWindow {
id: rootWindow
visible: true
width: 400
height: 200
title: qsTr("Hello World")
ScrollView {
anchors.fill: parent
flickableItem.flickableDirection: Flickable.VerticalFlick
Column {
Repeater {
model: 40
Slider {
width: rootWindow.width * 0.9
}
}
}
}
}
Looks like there was some attempt to fix this in the past, but not successful.
EDIT: this relates to Controls 1.x only, as controls doesn't seem to have this issue starting from 2.0 version.
You can place MouseAreas on the sliders to steal the mouse wheel event.
Something like this:
import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
ApplicationWindow {
id: rootWindow
visible: true
width: 400
height: 200
title: qsTr("Hello World")
ScrollView {
id: _scrollview
anchors.fill: parent
flickableItem.flickableDirection: Flickable.VerticalFlick
Column {
Repeater {
model: 40
Slider {
width: rootWindow.width * 0.9
property int scrollValue: 10
MouseArea {
anchors.fill: parent
onWheel: {
//check if mouse is scrolling up or down
if (wheel.angleDelta.y<0){
//make sure not to scroll too far
if (!_scrollview.flickableItem.atYEnd)
_scrollview.flickableItem.contentY += scrollValue
}
else {
//make sure not to scroll too far
if (!_scrollview.flickableItem.atYBeginning)
_scrollview.flickableItem.contentY -= scrollValue
}
}
onPressed: {
// forward mouse event
mouse.accepted = false
}
onReleased: {
// forward mouse event
mouse.accepted = false
}
}
}
}
}
}
}
Using the onWheel - event to forward any scrolling to the ScrollView. The other mouse events, such as clicking, can be forwarded to the parents (in this case the sliders) by setting mouse.accepted = false; for any mouse event you wish to have forwarded.
Edit: Oh, I just saw now that you don't want any changes in the sliders contents. You can also to try to place a MouseArea all over the ScrollView and do the same forwarding.
The easiest, if feasible for you, would probably be, to change from QtQuick.Controls 1.4 which can be either considered deprecated, not maintained, or low-performing to the new QtQuick.Controls 2.0
In this version your issue has been adressed.
To adress your need of QtQuick.Controls 1.4 we'll import the QtQuick.Controls 2.0 with an alias:
import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Controls 2.0 as NewCtrl
Column {
Slider {
id: oldslider // old slider from QtQuick.Controls 1.4 with your issue
width: 500
height: 250
}
NewCtrl.Slider {
id: newsli // new slider without your issue. Both side by side
width: 500
height: 30
wheelEnabled: false // use this to enable or disable the wheel
}
}
Of course you can also alias the old controls and use the new one as the basic... Or alias both. As you like
Hack from here did it for me.
Slider {
id: slider
Component.onCompleted: {
for (var i = 0; i < slider.children.length; ++i) {
if (slider.children[i].hasOwnProperty("onVerticalWheelMoved") && slider.children[i].hasOwnProperty("onHorizontalWheelMoved")) {
slider.children[i].destroy()
}
}
}
}
This may not work with other controls (e.g. ComboBox).

Qt5.5 image resizing jitter and not smooth

i'm learning Qt5. I start with a really simple QtQuick QML app with just one image filling the background. It works, but when i resize the window (Windows 8.1 64 bit), the resize is not smooth. There is substantial jitter and sometimes significant lag. It should be using OGL for this right?
Here's my code:
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("&Open")
onTriggered: console.log("Open action triggered");
}
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
}
MainForm {
anchors.fill: parent
}
}
and
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.2
Item {
visible: true
width: 640
height: 480
Image {
id: image1
sourceSize.height: 687
sourceSize.width: 1280
smooth: false
anchors.fill: parent
source: "images/showcase1280.jpg"
}
}
suggetions appreciated.
It is not smooth.
The image has a property named smooth the aim of which is to hold:
[...] whether the image is smoothly filtered when scaled or transformed.
Another interesting property is mimap, for which the documentation says that:
This property holds whether the image uses mipmap filtering when scaled or transformed.
Mipmap filtering gives better visual quality when scaling down compared to smooth, but it may come at a performance cost (both when initializing the image and during rendering).
Note that in your code you set:
smooth: false
Maybe you are doing it wrong if you want smooth changes, try setting the above mentioned properties to true.
I`m not pretend by solve your task. But i think you can use animation, as a variant:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1
Item {
Image {
anchors.centerIn: parent
width: parent.width
height: parent.height
sourceSize.height: 1000
sourceSize.width: 2000
source: "https://upload.wikimedia.org/wikipedia/ru/archive/8/88/20090512220306!Qt_logostrap_CMYK.png"
smooth: false
fillMode: Image.Stretch
asynchronous: true
Behavior on width {
animation: whAnimation
}
Behavior on height {
animation: whAnimation
}
NumberAnimation {
id: whAnimation
duration: 150
}
}
}

Take snapshot of video in Qt Multimedia

Is it possible to take snapshot of a video in Qt Multimedia? how?
It depends on the platform but what you can probably do is to use a QMediaPlayer, set a subclassed video surface via setVideoOutput, and get the frame data from the QVideoFrame passed in the present method. You'll then have to deal with the frame format and to map if those are not in CPU memory.
However, depending on your need, I would use ffmpeg/libav to get a frame from a specific position.
Try this (Documentation here: http://doc.qt.io/qt-5/qml-qtquick-item.html#grabToImage-method)
import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtMultimedia 5.0
Window {
id: mainWindow
visible: true
width: 480
height: 800
MediaPlayer {
id: player
source: "file:///location/of/some/video.mp4"
autoPlay: false
}
ColumnLayout {
anchors.fill: parent
VideoOutput {
id: output
source: player
Layout.fillHeight: true
Layout.fillWidth: true
}
Row {
id: buttonsRow
height: 100
spacing: 20
anchors.horizontalCenter: parent.horizontalCenter
Layout.margins: 10
Button {
id: playPauseButton
text: player.playbackState === MediaPlayer.PlayingState ? "Pause" : "Play"
onClicked: {
var playing = player.playbackState === MediaPlayer.PlayingState;
playing ? player.pause() : player.play();
}
}
Button {
text: "Snapshot"
onClicked: {
output.grabToImage(function(image) {
console.log("Called...", arguments)
image.saveToFile("screen.png"); // save happens here
});
}
}
}
}
}

QML Audio stops 400 milliseconds before the end

Can someone, please, explain this odd behavior of my application.
I am using Qt 5.1.0 and msvc2010.
This is my code:
import QtQuick 2.1
import QtQuick.Window 2.1
import QtMultimedia 5.0
Window {
visible: true
width: 360
height: 360
MouseArea {
anchors.fill: parent
onClicked: {
playAudio.play()
}
}
Audio {
id: playAudio
source: "zvuky/1.mp3"
}
}
Your code doesn't have any error. Maybe it's due to the mp3 file and Qt is not able to load it.
Did you try to convert the mp3 file to wav? Sometimes it's better to use SoundEffect instead of Audio.
You could also try the MediaPlayer type.
Here you have an example. It's in GitHub where you can download the audio clips.
import QtQuick 2.5
import QtQuick.Window 2.2
import QtMultimedia 5.4
Window {
visible: true
width: 360
height: 360
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
if (mouse.button == Qt.RightButton)
playMP3.play()
else
playWAV.play()
}
}
SoundEffect {
id: playWAV
source: "res/kid_giggle.wav"
onPlayingChanged: {
console.log("SoundEffect - onPlayingChanged - category: " + category)
}
}
MediaPlayer {
id: playMP3
source: "res/kid_giggle.mp3"
onPlaying: {
console.log("MediaPlayer - onPlaying - duration: " + duration)
}
}
}
Finelly I found solution.
Everything works perfect with Audio element when I used Qt 5.2.1(msvc2012)

Resources