发送信号后,如何在QML中刷新一个组件



基本上,我在QML中有一个组合框,我使用QSTRINGLIST填充。但是,我无法刷新组合框(重新加载(以显示列表已更改。我考虑使用装载机这样做,但我无法弄清楚。有人可以指导我如何做。

network.qml

Popup{
    contentItem: Rectangle{
        LabelValueList {
            id: list1
            row1: LabelValue {
                id: row1
            row2: LabelValue {
                id: row2
                value: ComboBox {
                    id: combobox
                    model: ListModel {
                        id: comboModel
                        Component.onCompleted: {
                            //..
                            }
                        }
                    }
                }
            }
        }
    }
}

network.h

class Network : public QObject{
    Q_OBJECT
    Q_PROPERTY(QStringList listOfNetworks READ m_listOfNetworks NOTIFY updateNetworks)
    private:
        QStringList m_listOfNetworks;
    public:
        explicit Network(QObject *parent = 0);
        QStringList listOfNetworks() const;
    public slots:
        void slot_scanNetworks();
    signals:
        void updateNetworks();
};

network.cpp

Network::Network(QObject *parent) : QObject (parent){
}
void Network::slot_scanNetworks(){
    QFile SSIDsFile("/home/root/networking/listOfWifiNetworks.txt");
    m_listOfNetworks.clear();
    if (!SSIDsFile.open(QIODevice::ReadOnly | QIODevice::Text)){
    //
    }
    else{
        QTextStream scanNetworkStream(&SSIDsFile);
        while (!scanNetworkStream.atEnd()){
            QString line = scanNetworkStream.readLine();
            if (line.size() != 0){
                QStringList lineSplit = line.split(' ');
                m_listOfNetworks.append(lineSplit[1]);
            }
        }
    }
    SSIDsFile.close();
    emit updateNetworks();
}

如何重新加载Row2的组合框以刷新列表?它仅在开始时获得列表,但是当我发出信号updateNetworks((时,我想更新下拉下拉(Combo-Box(。我尝试使用加载程序并将其设置为Row2的ID,但我一直在遇到错误"错误:无法将QObject*分配给qqmlcomponent"。有帮助吗?

我不是专业人士,但也许可以帮助您这篇文章。您可以在UR应用程序上使用计时器并设置1来刷新此功能并进行变量,并且呼叫信号呼叫此变量时示例:

// make a variable type of bool by value = false
property bool refreshMyBoxNow : false 

//add this timer to ur project 
    Timer
    {
        id: timeToRefreshBox 
        //interval = time to tick . (1000) = 1sec 
        interval: 1; running: true; repeat: true
        onTriggered:
        {
             //your code here for refresh box
        }
    }

相关内容

  • 没有找到相关文章

最新更新