首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > QT开发 >

QML生手

2013-04-20 
QML新手 请教大家一个问题:我想用qml做一个photo view ,用的是qml自带的例子photoviewer。但是我想实现的是

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++ 
  }
}

热点排行