PDA

View Full Version : Bug on load image or video to QML using C++



prchakal
27th January 2014, 15:39
Hi,

I made a project for a church that show images on projector.

On my mac(osx 10.9) and ubuntu linux 13, everything is working nice, but on Windows machine the exact software dont load the images to QML and dont load vÃ*deos to MediaPlayer.

This problems i only get on Windows.

The example project of loading video on QML works nice, but everything is done inside a QML application.

My application change the image and video dynamic invoking a method. Look the code:

FROM MY C++ APP:


QString fullFilePath = "file://C:/PRProjector-Project/data/images/allthingsnew-background.jpg";
QMetaObject::invokeMethod(rootObject, "loadBackgroundImage", Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, fullFilePath));


FROM MY QML FILE:


import QtQuick 2.2
import QtMultimedia 5.2
import QtGraphicalEffects 1.0
Item {
function loadBackgroundImage(fullFilePath)
{ backgroundImage.source = fullFilePath; }
Image
{ id: backgroundImage objectName: "backgroundImage" source: "" anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter anchors.fill: parent; }
}


ERROR:


qrc:/resources/qml/ProjectorScreen.qml:36:5: QML Image: Cannot open:

Also, I got error error event on MediaPlayer object from QML when i try load some video too.

REMEMBER: IT IS WORKING IN MAC OSX AND LINUX!

anda_skoa
27th January 2014, 19:30
QUrl::fromLocalFile()

Btw, it is way more elegant to expose such a thing as a context property instead of calling into the QML scene.

Cheers,
_

prchakal
27th January 2014, 19:54
Hi,

I have tested QUrl::fromLocalFile() before. But i will try again.

But what the correct syntax?



QString fullFilePath = QUrl::fromLocalFile("file://C:/PRProjector-Project/data/images/allthingsnew-background.jpg").toString()
or
QString fullFilePath = QUrl::fromLocalFile("C:/PRProjector-Project/data/images/allthingsnew-background.jpg").toString()
or
QString fullFilePath = QUrl::fromLocalFile("C:\\PRProjector-Project\\data\\images\\allthingsnew-background.jpg").toString()


Thanks man.

wysota
27th January 2014, 20:39
Also make sure you have the imageplugin for JPEG images available.

prchakal
27th January 2014, 20:51
Hi,

The images/videos load normal when everything is set inside the QML. The problem is only on WINDOWS when i SET the path with C++.

Whats the correct way based on my last question?

anda_skoa
28th January 2014, 08:45
But what the correct syntax?



QString fullFilePath = QUrl::fromLocalFile("file://C:/PRProjector-Project/data/images/allthingsnew-background.jpg").toString()
or
QString fullFilePath = QUrl::fromLocalFile("C:/PRProjector-Project/data/images/allthingsnew-background.jpg").toString()
or
QString fullFilePath = QUrl::fromLocalFile("C:\\PRProjector-Project\\data\\images\\allthingsnew-background.jpg").toString()



Not the first one, that is a URL as input.
My guess is that both other ones should work.
If you want to be sure use QFileDialog to get the filename and have a look at it.

Btw, I don't think there is a need for the toString() call, just send the QUrl to the QML engine.

Cheers,
_

prchakal
28th January 2014, 15:08
Hi

I solve the problem using only:

file:C:/PRProjector-Project/data/images/allthingsnew-background.jpg

Thanks.