Results 1 to 6 of 6

Thread: Remove signal?

  1. #1
    Join Date
    Nov 2012
    Posts
    47
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Remove signal?

    I want my app to login to a site, but first it needs to go to the mainpage and get a session id.

    Qt Code:
    1. QNetworkAccessManager *manager = new QNetworkAccessManager;
    2. QNetworkRequest request;
    3. request.setUrl(furl);
    4.  
    5. //SIGNAL SLOT
    6. connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(Getreply(QNetworkReply*)));
    7.  
    8. manager->get(request);
    To copy to clipboard, switch view to plain text mode 

    And then I get the session ID at the Getreply slot. Next, I need to post data, username and password.

    Qt Code:
    1. void Getreply()
    2. {
    3. //Edit parameters, url etc....
    4. connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(Getlogin(QNetworkReply*)));
    5.  
    6. manager->post(request)
    7. }
    To copy to clipboard, switch view to plain text mode 

    Getlogin will have codes like check if login success and so on..


    This first problem is, when the manager signal emits finished(QNetworkReply*) in Getreply(), I believe not only Getlogin will run, but also Getreply, because both are now connected signal slots. How can I turn the first "connect" off, or what other solution can I have.

    Second, I created all the variables on the first function, but then I need to edit stuff like post data at the second function, Getreply, i'm forced to make them global. Any other ways?

    Thx.
    I'm a newbie. Don't trust me

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Remove signal?

    You can disconnect() the same way you connect().

    You can check the slot argument and return if it is not the one you want to handle in a given slot.

    You can connect to the QNetworkReply's finished() signal and only get your slot invoked when that particular request finished.

    You don't need global variables, just put the manager into a member of the class that has these methods or access the manager from the QNetworkReply object

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    ttimt (30th March 2015)

  4. #3
    Join Date
    Nov 2012
    Posts
    47
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Remove signal?

    Quote Originally Posted by anda_skoa View Post
    You can check the slot argument and return if it is not the one you want to handle in a given slot.
    _
    You mean since I know what data to expect, I can verify it?

    Then if I have codes below manager->post, those might be executed before slot returns. I can use QEventloop rite.


    Quote Originally Posted by anda_skoa View Post
    You can connect to the QNetworkReply's finished() signal and only get your slot invoked when that particular request finished.
    _
    I can connect finished() to the two slot() and invoke one of them? can you explain further? or example.. thankss
    Last edited by ttimt; 30th March 2015 at 19:05.
    I'm a newbie. Don't trust me

  5. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Remove signal?

    Here's how I handle this... I use the QNetworkAccessManager::finished signal to log all HTTP results, period. I then connect the individual QNetworkReply::finished signal to manage the results of the request.

    So QNetworkAccessManager::finished is used only for logging the request's status and all processing handled in the individual request/reply finished signals.

    If you only care about managing the reply, then I recommend you use the reply pointer returned by QNetworkRequest and connect a slot to the &QNetworkReply::finished signal.

    Hope that helps.

  6. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Remove signal?

    Quote Originally Posted by ttimt View Post
    You mean since I know what data to expect, I can verify it?
    The signal transports the QNetworkReply object that was finished, which allows you to access the QNetworkRequest that was used to create it.
    So you could check the URL, for example.

    Quote Originally Posted by ttimt View Post
    Then if I have codes below manager->post, those might be executed before slot returns. I can use QEventloop rite.
    Why would you want to do that?

    Quote Originally Posted by ttimt View Post
    I can connect finished() to the two slot() and invoke one of them? can you explain further? or example.. thankss
    Why do you want to connect to two slots when you want one to be invoked?
    That kind of defeats your goal, doesn't it?

    I.e. what would you gain from connecting the finished() signal of the first request to the slot handling the second one?

    Cheers,
    _

  7. #6
    Join Date
    Nov 2012
    Posts
    47
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Remove signal?

    Quote Originally Posted by anda_skoa View Post
    The signal transports the QNetworkReply object that was finished, which allows you to access the QNetworkRequest that was used to create it.
    So you could check the URL, for example.


    Why would you want to do that?


    Why do you want to connect to two slots when you want one to be invoked?
    That kind of defeats your goal, doesn't it?

    I.e. what would you gain from connecting the finished() signal of the first request to the slot handling the second one?

    Cheers,
    _
    Okay thanks
    I'm now using "disconnect"
    I'm a newbie. Don't trust me

Similar Threads

  1. Replies: 1
    Last Post: 14th August 2014, 17:08
  2. Replies: 7
    Last Post: 20th March 2014, 07:43
  3. Replies: 6
    Last Post: 4th March 2014, 15:09
  4. How to connect signal to signal in QWidget correctly
    By Mint87 in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2013, 00:06
  5. Replies: 3
    Last Post: 2nd April 2011, 13:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.