Reply
Thread Tools
Posts: 1,086 | Thanked: 2,964 times | Joined on Jan 2010
#1
As part of mfakecaller i want the user to be able to input an image path and the app will display the image if it is found, else a 'not found' warning image would be displayed instead. The mfakecaller application GUI Im working on is created in QML, a Text Input takes the file path for the caller image and an Image item displays it by assigning that path to it's source.



Basically what I would like is something simple:

Code:
if (filepath exists)
  image.source = filepath;
else 
  image.source = "imagenotfound.jpg"
I couldn't find any info on error handling loading of an image in QML, does anyone know how to do this in the QML? Instead I tried to use JavaScript to do this using the info i found on this page

Code:
function testImage(URL) {
    var tester=new Image();
    tester.onLoad=isGood;
    tester.onError=isBad;
    tester.src=URL;
}
It seemed simple enough - if you can load the image then it must exist - so I created a function to return true or false on onLoad. However I am receiving a type error running the code on the N900.

Code:
function findImage(inputPath)
{
    var image2Find = new Image();
    ....
At this point it throws the error

Code:
TypeError: Result of expression 'Image' [[object Object]] is not a constructor.
Can anyone advise me how to debug this or know a simpler way of checking if a file exists in QML projects? My C++ skills are not so good so I'd prefer a non-C++ method if possible.

Also, ideally I would like a file dialog but there's no handy QML item for that in the Qt Designer, such as Text Input, that would call the underlying OS file dialog. Anyone know a simple way/tutorial for that too?

Thanks!
__________________
Follow me on my neglected twitter @kojacker

Cybot950 - Control a robot with your N9/N950
SMSPetFeeder - Build a Bluetooth/SMS dog feeder with Qt, N950, and arduino
Nerf950 - Use your N9/N950 to fire a Nerf gun

Last edited by kojacker; 2010-12-18 at 04:08.
 
Reply


 
Forum Jump


All times are GMT. The time now is 03:52.