question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[REQ] [Qt5] Emit a generic signal anytime an api call is completed

See original GitHub issue

The current callback in the API interface emits signals specific to the API, for example

    if (worker->error_type == QNetworkReply::NoError) {
        emit createUsersWithArrayInputSignal();
        emit createUsersWithArrayInputSignalFull(worker);
    } else {
        emit createUsersWithArrayInputSignalE(error_type, error_str);
        emit createUsersWithArrayInputSignalEFull(worker, error_type, error_str);
    }

From the outside we can then connect to these signals

The API has different signals per function call.

I would like to be able to know if the API did “any work” not just some “specific work”

For example I would add a signal called void workDone()

    if (worker->error_type == QNetworkReply::NoError) {
        emit createUsersWithArrayInputSignal();
        emit createUsersWithArrayInputSignalFull(worker);
    } else {
        emit createUsersWithArrayInputSignalE(error_type, error_str);
        emit createUsersWithArrayInputSignalEFull(worker, error_type, error_str);
    }

    emit workDone();
    if (worker->error_type == QNetworkReply::NoError) {
        emit createUsersWithListInputSignal();
        emit createUsersWithListInputSignalFull(worker);
    } else {
        emit createUsersWithListInputSignalE(error_type, error_str);
        emit createUsersWithListInputSignalEFull(worker, error_type, error_str);
    }

    emit workDone();

and this would be added to ALL of the callback functions. From the outside then we could connect to know if the API class has done anything yet without needing to connect to a whole bunch of individual signals

This would be trivial for me to add so I wanted to open it up for discussion before just adding a PR

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
etherealjoycommented, Mar 3, 2021

We don’t use the same worker for all calls to a single api class necessarily though? We create one dynamically in each function, so the find children would only apply to that one worker

That is right, so whenever any worker is destroyed we check in the lambda if this which is the API object has any worker remaining. When all workers are destroyed (triggered by abort, timeout and network responses) the current API object will have no more workers and therefore no more active request.

1reaction
etherealjoycommented, Mar 3, 2021

OK thank you for elaborating the use case. What I was trying to say is that, using your example

void doThing1Somewhere() {
  PFXUserApi* api = new PFXUserApi();
  connect(api, &PFXUserApi::addPetSignal, this, function to process doing this);
  connect(api, &PFXUserApi::addPetSignalE, this, function to process an error when doing this);
  api.addPet(pet1ToAdd);
  api.deletePet(pet2ToDelete);
  m_manager->addTask(api);
}

In the above case, It is unknown whether signal callbackExecutedSignal() comes from deletePet() or addPet(). Maybe not an issue in this case since you only care if the call was completed. But if we were to make a feature we should handle the case where we have to emit the signal when all pending request from that object have been done or timed out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Signals & Slots | Qt Core 6.4.1
A signal is emitted when a particular event occurs. Qt's widgets have many predefined signals, but we can always subclass widgets to add...
Read more >
QThread emits finished() signal but isRunning() returns true ...
The function locateMe() is called whenever a button is clicked. The first time when the thread isnt started and the button is clicked...
Read more >
Transmit extra data with signals in PyQt5 - Python GUIs
The triggered signal emits a single piece of data -- the checked state ... SIGNAL: The connected function will be called whenever the...
Read more >
Understanding the mechanism of signals and slots | Qt 5 ...
Since Qt uses a mechanism called signals and slots, it makes the callback function weakly coupled to the event. Also, we usually use...
Read more >
qnetworkreply.cpp source code [qtbase/src/network/access ...
82, network and processed, the readyRead() signal is emitted. ... 187, \value ContentConflictError the request could not be completed due.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found