简体   繁体   中英

Change QML Image source from C++

if you look at my sample below I can alter the properties of QML objects from my C++ code using QT.

C++

QQuickItem* objectimage = quickView->rootObject();
QObject *im = objectimage->findChild<QObject*>("rect");
im->setProperty("color", "red");

QML

Image {
    objectName: "ima"
    id:pic
    source: "bgnight.png"

    Rectangle{   
        objectName: "rect"
        id:redRect1
        width: 100
        height: 100
        x: 130
        y:230
        color:"transparent"

My question is how do you change the source of an image in the same way from C. I would like to change the background image of QML from C++.

Image 
{
    property string src: "bge.png"
    source: src

    objectName: "ima"
    id:pic
}

Qt 只有 C++ api,但您可以创建具有 C 函数定义但具有 C++ 实现的单独包装库

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM