Qt Quick dynamicaly add page to swipe view



  • Hello,
    I have class in c++ for network listenig on multicast that have a function which emits signal:

    public slot:
    void listenOnPort(int port);
    
    signals:
    void multicastReceived(QString msg);
    

    Its just part of bigger software with Gui in qml with swipe view as main part:

        SwipeView {
            id: swipeView
            anchors.fill: parent      
            currentIndex: tabBar.currentIndex
            MainPage {
            }
    .
    .
    .
        }
    

    And I need that when the qml receives the signal from c++. It dynamicaly add new page (just with some text holder) to swipe view where the received message from multicast will be displayed.

    Can someone help me with this dynamic adding to swipe view please. If it's even possible :-)

    Thanks soo much to everyone :-)


  • Moderators

    Hi! SwipeView is a Container QML Type. So you should be able to pages to it using void addItem(Item item).



  • Great thanks it works. My example solution:

        SwipeView {
            id: swipeView
            anchors.fill: parent    
            MainPage {
            }
    
            function addPage(page) {
               addItem(page)
               page.visible = true
            }
    
            function removePage(page) {
               for (var n = 0; n < count; n++) { if (page === itemAt(n)) { removeItem(n) } }
               page.visible = false
            }
        }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.