Results 1 to 7 of 7

Thread: Bug on load image or video to QML using C++

  1. #1
    Join Date
    Mar 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Bug on load image or video to QML using C++

    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:

    Qt Code:
    1. QString fullFilePath = "file://C:/PRProjector-Project/data/images/allthingsnew-background.jpg";
    2. QMetaObject::invokeMethod(rootObject, "loadBackgroundImage", Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, fullFilePath));
    To copy to clipboard, switch view to plain text mode 

    FROM MY QML FILE:

    Qt Code:
    1. import QtQuick 2.2
    2. import QtMultimedia 5.2
    3. import QtGraphicalEffects 1.0
    4. Item {
    5. function loadBackgroundImage(fullFilePath)
    6. { backgroundImage.source = fullFilePath; }
    7. Image
    8. { id: backgroundImage objectName: "backgroundImage" source: "" anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter anchors.fill: parent; }
    9. }
    To copy to clipboard, switch view to plain text mode 

    ERROR:

    Qt Code:
    1. qrc:/resources/qml/ProjectorScreen.qml:36:5: QML Image: Cannot open:
    To copy to clipboard, switch view to plain text mode 

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Bug on load image or video to QML using C++

    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,
    _

  3. #3
    Join Date
    Mar 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Re: Bug on load image or video to QML using C++

    Hi,

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

    But what the correct syntax?

    Qt Code:
    1. QString fullFilePath = QUrl::fromLocalFile("file://C:/PRProjector-Project/data/images/allthingsnew-background.jpg").toString()
    2. or
    3. QString fullFilePath = QUrl::fromLocalFile("C:/PRProjector-Project/data/images/allthingsnew-background.jpg").toString()
    4. or
    5. QString fullFilePath = QUrl::fromLocalFile("C:\\PRProjector-Project\\data\\images\\allthingsnew-background.jpg").toString()
    To copy to clipboard, switch view to plain text mode 

    Thanks man.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Bug on load image or video to QML using C++

    Also make sure you have the imageplugin for JPEG images available.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Re: Bug on load image or video to QML using C++

    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Bug on load image or video to QML using C++

    Quote Originally Posted by prchakal View Post
    But what the correct syntax?

    Qt Code:
    1. QString fullFilePath = QUrl::fromLocalFile("file://C:/PRProjector-Project/data/images/allthingsnew-background.jpg").toString()
    2. or
    3. QString fullFilePath = QUrl::fromLocalFile("C:/PRProjector-Project/data/images/allthingsnew-background.jpg").toString()
    4. or
    5. QString fullFilePath = QUrl::fromLocalFile("C:\\PRProjector-Project\\data\\images\\allthingsnew-background.jpg").toString()
    To copy to clipboard, switch view to plain text mode 
    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,
    _

  7. #7
    Join Date
    Mar 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Bug on load image or video to QML using C++

    Hi

    I solve the problem using only:

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

    Thanks.

Similar Threads

  1. image.load
    By Arend in forum Newbie
    Replies: 2
    Last Post: 20th May 2013, 20:52
  2. how to load image from one ui to another
    By trupti in forum Newbie
    Replies: 4
    Last Post: 3rd January 2011, 13:03
  3. how do load image
    By yuvaraj.yadav in forum Qt Programming
    Replies: 5
    Last Post: 21st April 2009, 06:31
  4. Is there a better way to load a big image?
    By learning_qt in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2008, 16:00
  5. best way to load image from db
    By C167 in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2008, 19:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.