Important: Please read the Qt Code of Conduct -

Connect return of a method to signal - possible?

  • Hi Qt-fans,

    I started some time ago with Qt (in PySide) and working now with C++ (where I am new - more or less). And I want to request data from TheMovieDB API with a getPopularMovies() method that should return a list of "MovieObjects" - they are holding just some arguments (Title, Image path ...) and have some get/set methods.

    My problem is the following:
    To do the request I use QNetworkManager's get method, which works pretty well, but due to the async nature it seems you should/have to connect the finished() signal to a SLOT. So I can't do the request and everything else (like parsing response) in one method. So I connected it to an evauate slot, that reads the JSON data from QNetworkReply and creates a list of MovieObjects. After they are created a finished() signal I implemented is emited.

    It would be great, if I could use return in getPopularMovies(), depending on my finished signal. Say something like that: connect(this, SIGNAL(myFinishedSignal), return <My list of objects>)

    Is something like that possible?

    Or do I need another function, to get the list? So that I call first searchPopularMovies() and than after this is finished a getPopularMovies() method?

    Thanks in advance, AlphaX2.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You can't do that like that, signals only have void as return type and also no implementation.

    What you can do however is emit a signal with your MovieObjects list as a parameter.

    Hope it helps

Log in to reply