Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Receive signal once for each element

QML Receive signal once for each element

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 282 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AriosJentu
    wrote on last edited by AriosJentu
    #1

    Hi. I have a problem with receiving signals. I need to get only one signal for element, when it initialize, but I've got for each element too much signals with almost same value. My code looks like this:

    CalendarView.qml

    ....
    Item {
        ....
        property bool visibility: false;
        Component.onCompleted: {
            eventModel.eventsCountForDate(styleData.date);
            eventModel.eventsCount.connect(setVisible);
        }
    
        function setVisible(result) {
            visibility = result > 0;
        }
    
        Image {
    
            visible: visibility
            ....
            source: "qrc:/assets/event.png"
        }
        ....
    }
    

    Item's parent element has property for date, called styleData.date.
    My functions, which calls GET request from server:

    void EventModel::replyCountFunction(QNetworkReply* reply) {
    
        //Test for errors, and get reply data
    
        emit eventsCount(response.getCount());
    
        return;
    }
    
    void EventModel::eventsCountForDate(const QDate &date) {
    
        //Work with date and request
    
        QNetworkAccessManager* manager = new QNetworkAccessManager();
        
        QObject::connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyCountFunction(QNetworkReply*)), Qt::UniqueConnection);
        manager->get(request);
    
    }
    

    When I debug this, I've got that onComplete QML parameter calls correct, which calling function eventCountForDate, which calls correct too, for my calendar it's 42 times, for each date in visible part of calendar. And function replyCountFunction, also works 42 times, but for each time, it sends back to QML function setVisible for 42 times per one calling reply function. My log looks like this:

    .....
    Calling function replyCountFunction
    qml: Connected 0
    qml: Connected 0
    ..... //another 39 times 
    qml: Connected 0
    Calling function replyCountFunction
    qml: Connected 0
    qml: Connected 0
    .....
    

    Where 0 is count of events for day. Sometimes it will send me 42 "one's" (1) for one reply, it happens too.
    I think, reason in connect function, maybe I need to disconnect function for manager, but I create a custom manager in each calling of eventsCountForDate. I had almost the same problem, but for single date, when I search events for selected date, and it fixed by separating NetworkAccessManager for each request (cause I've used one network manager for two requests - get list of events for date in one request, and get event parameters in another request). But here it's not working.
    Maybe you know, how can I organize this work. Thank you.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved