读书人

QML生手

发布时间: 2013-04-20 19:43:01 作者: rapoo

QML新手
请教大家一个问题:我想用qml做一个photo view ,用的是qml自带的例子photoviewer。但是我想实现的是能够自动加载某一文件夹下的所有图片,就是qml 语言获取本地文件夹中所有图片,显示出来,请问怎么实现呢? 我刚自学QML,只懂Qt,才,c++,对JS不是很懂。
[解决办法]
应该要用到和C++交互吧

用C++从文件夹读取然后传给QML显示出来
[解决办法]
main.cpp:

QApplication app(argc, argv);
QDeclarativeView myView;
QDeclarativeEngine *engine=myView->engine();
QDeclarativeContext *context=engine->rootContext();
QString imgSource ="";//image sourece
context->setContextProperty("myImgSource",imgSource);
myView->setSource("main.qml");//qml source
myView->show();
return app.exec();


main.qml:

Rectangle{
width:200
height:200
color:"red"
Image{
width:100
height:100
source: myImgSource//c++
}
}

读书人网 >QT开发

热点推荐